Python package to allow easy integration to Neo4j's GenAI features
Project description
Neo4j GenAI package for Python
This repository contains the official Neo4j GenAI features for Python.
Usage
Installation
This package requires Python (>=3.8.1).
To install the latest stable version, use:
pip install neo4j-genai
Example
After setting up a Neo4j database instance:
from neo4j import GraphDatabase
from neo4j_genai import VectorRetriever
from random import random
from neo4j_genai.indexes import create_vector_index
URI = "neo4j://localhost:7687"
AUTH = ("neo4j", "password")
INDEX_NAME = "embedding-name"
DIMENSION = 1536
# Connect to Neo4j database
driver = GraphDatabase.driver(URI, auth=AUTH)
# Creating the index
create_vector_index(
driver,
INDEX_NAME,
label="Document",
property="propertyKey",
dimensions=DIMENSION,
similarity_fn="euclidean",
)
# Initialize the retriever
retriever = VectorRetriever(driver, INDEX_NAME)
# Upsert the vector
vector = [random() for _ in range(DIMENSION)]
insert_query = (
"MERGE (n:Document {id: $id})"
"WITH n "
"CALL db.create.setNodeVectorProperty(n, 'propertyKey', $vector)"
"RETURN n"
)
parameters = {
"id": 0,
"vector": vector,
}
driver.execute_query(insert_query, parameters)
# Perform the similarity search for a vector query
query_vector = [random() for _ in range(DIMENSION)]
print(retriever.search(query_vector=query_vector, top_k=5))
Development
Install dependencies
poetry install
Getting started
Issues
If you have a bug to report or feature to request, first search to see if an issue already exists. If a related issue doesn't exist, please raise a new issue using the relevant issue form.
If you're a Neo4j Enterprise customer, you can also reach out to Customer Support.
If you don't have a bug to report or feature request, but you need a hand with the library; community support is available via Neo4j Online Community and/or Discord.
Make changes
- Fork the repository.
- Install Python and Poetry. For more information, see the development guide.
- Create a working branch from
main
and start with your changes!
Pull request
When you're finished with your changes, create a pull request, also known as a PR.
- Ensure that you have signed the CLA.
- Ensure that the base of your PR is set to
main
. - Don't forget to link your PR to an issue if you are solving one.
- Enable the checkbox to allow maintainer edits so that maintainers can make any necessary tweaks and update your branch for merge.
- Reviewers may ask for changes to be made before a PR can be merged, either using suggested changes or normal pull request comments. You can apply suggested changes directly through the UI, and any other changes can be made in your fork and committed to the PR branch.
- As you update your PR and apply changes, mark each conversation as resolved.
Run tests
Open a new virtual environment and then run the tests.
poetry shell
pytest
Further information
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for neo4j_genai-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89ef2f0cd40ca93bd1bedf139d249e9144a1418c9da6b4af55ff6faf3eb7abc9 |
|
MD5 | 8bf0764203609187975d4a842266b091 |
|
BLAKE2b-256 | bf50ba36baab043311271cf2a771892c7495cd55c121694213481b9d5cf4b708 |