diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3980af8b4..97f3677f7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,3 +4,11 @@ repos: hooks: - id: trailing-whitespace - id: end-of-file-fixer + - repo: local + hooks: + - id: ruff-lint + name: Ruff Lint Check + entry: poetry run ruff format --check + language: system + types: [ python ] + stages: [ commit, push ] diff --git a/docs/Makefile b/docs/Makefile index f603d9849..8f86c88ee 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -5,13 +5,13 @@ VERSION = 0.1.2 PRODUCT = neo4j-genai-python SPHINXOPTS = -SPHINXBUILD = sphinx-build +SPHINXBUILD = poetry run sphinx-build PAPER = BUILDDIR = build -# User-friendly check for sphinx-build -ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) -$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from https://www.sphinx-doc.org/) +# User-friendly check for sphinx-build via Poetry +ifeq ($(shell poetry run which sphinx-build >/dev/null 2>&1; echo $$?), 1) +$(error The 'sphinx-build' command was not found within the Poetry environment. Make sure Sphinx is installed in your project dependencies.) endif # Internal variables. diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 000000000..fd8f5ffde --- /dev/null +++ b/docs/README.md @@ -0,0 +1,16 @@ +# Sphinx Documentation + +Building the docs requires Python 3.8.1+ + +Ensure the dev dependencies in `pyproject.toml` are installed. + +From the root directory, run the Makefile: + +``` +make -C docs html +``` + +You can now view your build locally. + +When you open a PR, a TeamCity build will trigger when it's ready and someone from Neo4j +can then preview this. diff --git a/docs/source/README.md b/docs/source/README.md deleted file mode 100644 index 5e995465e..000000000 --- a/docs/source/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# Sphinx Documentation - -Building the docs requires Python 3.8.1+ - -Ensure the dev dependencies in `pyproject.toml` are installed. - -From the root directory -``` -make -C docs html -``` - -``` -python -m sphinx -b html docs/source docs/build/html -``` diff --git a/docs/source/index.rst b/docs/source/index.rst index 0a60aee9e..034675425 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -62,6 +62,7 @@ Performing a similarity search from neo4j import GraphDatabase from neo4j_genai import VectorRetriever + from langchain_openai import OpenAIEmbeddings URI = "neo4j://localhost:7687" AUTH = ("neo4j", "password") @@ -71,8 +72,11 @@ Performing a similarity search # Connect to Neo4j database driver = GraphDatabase.driver(URI, auth=AUTH) + # Create Embedder object + embedder = OpenAIEmbeddings(model="text-embedding-3-large") + # Initialize the retriever - retriever = VectorRetriever(driver, INDEX_NAME) + retriever = VectorRetriever(driver, INDEX_NAME, embedder) # Run the similarity search query_text = "How do I do similarity search in Neo4j?" @@ -219,6 +223,42 @@ Open a new virtual environment and then run the tests. poetry shell pytest +~~~~~~~~~~ +Unit tests +~~~~~~~~~~ + +This should run out of the box once the dependencies are installed. + +.. code:: bash + + poetry run pytest tests/unit + +~~~~~~~~~ +E2E tests +~~~~~~~~~ + +To run e2e tests you'd need to have some services running locally: + +- neo4j +- weaviate +- weaviate-text2vec-transformers + +The easiest way to get it up and running is via Docker compose: + +.. code:: bash + + docker compose -f tests/e2e/docker-compose.yml up + + +.. note:: + + If you suspect something in the databases are cached, run `docker compose -f tests/e2e/docker-compose.yml down` to remove them completely + +Once the services are running, execute the following command to run the e2e tests. + +.. code:: bash + + poetry run pytest tests/e2e ******************* Further information diff --git a/src/neo4j_genai/retrievers/vector.py b/src/neo4j_genai/retrievers/vector.py index 80aa3ebbb..894876f44 100644 --- a/src/neo4j_genai/retrievers/vector.py +++ b/src/neo4j_genai/retrievers/vector.py @@ -115,7 +115,7 @@ def search( Returns: list[VectorSearchRecord]: The `top_k` neighbors found in vector search with their nodes and scores. - """ + """ try: validated_data = VectorSearchModel( vector_index_name=self.index_name,