From 0f3a4a974ede1e9ebc42e53506cb328e8f9140b2 Mon Sep 17 00:00:00 2001 From: Will Tai Date: Wed, 1 May 2024 17:32:44 +0100 Subject: [PATCH] Added src to docs retriever import --- docs/Makefile | 6 ++++-- docs/source/api.rst | 11 ++++++++++- docs/source/conf.py | 15 +++++++++++++++ docs/source/index.rst | 7 ++++++- docs/source/types/vector.rst | 11 +++++++++++ src/neo4j_genai/retrievers/hybrid.py | 6 +++--- src/neo4j_genai/retrievers/vector.py | 22 +++++++++++++++------- src/neo4j_genai/types.py | 8 ++++++++ 8 files changed, 72 insertions(+), 14 deletions(-) create mode 100644 docs/source/types/vector.rst diff --git a/docs/Makefile b/docs/Makefile index 1bc069807..f603d9849 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -2,6 +2,8 @@ # # You can set these variables from the command line. +VERSION = 0.1.2 +PRODUCT = neo4j-genai-python SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = @@ -52,9 +54,9 @@ clean: rm -rf $(BUILDDIR)/* html: - $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/$(PRODUCT)/$(VERSION) @echo - @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + @echo "Build finished. The HTML pages are in $(BUILDDIR)/$(PRODUCT)/$(VERSION)." dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml diff --git a/docs/source/api.rst b/docs/source/api.rst index 8dc0b4749..9f7bd31a4 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -21,7 +21,6 @@ VectorRetriever .. autoclass:: neo4j_genai.retrievers.vector.VectorRetriever :members: - VectorCypherRetriever ===================== @@ -41,3 +40,13 @@ HybridCypherRetriever .. autoclass:: neo4j_genai.retrievers.hybrid.HybridCypherRetriever :members: + + + +********** +Data Types +********** + +.. include:: types/_vector-search-record-types.rst + +See topic :ref:`vector-search-record-types` for more details. diff --git a/docs/source/conf.py b/docs/source/conf.py index 2511ac3cd..f7d2acd43 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -13,6 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os +import sys + +# Add the root of the project to the path so that Sphinx can find the Python sources +sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..")) + # Configuration file for the Sphinx documentation builder. # # For the full list of built-in configuration values, see the documentation: @@ -35,8 +41,14 @@ "sphinx.ext.coverage", "sphinx.ext.ifconfig", "sphinx.ext.intersphinx", + "sphinx.ext.napoleon", + "sphinx.ext.viewcode", ] +intersphinx_mapping = { + "python": ("https://docs.python.org/3", None), +} + templates_path = ["_templates"] exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] @@ -46,3 +58,6 @@ html_theme = "neo4j" html_theme_path = ["themes"] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = "sphinx" diff --git a/docs/source/index.rst b/docs/source/index.rst index c1c307077..cab0617d6 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -16,11 +16,16 @@ fast to ship new features and high performing patterns and methods. Topics ****** ++ :ref:`api-documentation` ++ :ref:`vector-search-record-types` + .. toctree:: - :maxdepth: 2 + :maxdepth: 3 :caption: Contents: + :hidden: api.rst + types/vector.rst Usage diff --git a/docs/source/types/vector.rst b/docs/source/types/vector.rst new file mode 100644 index 000000000..3ed971ea5 --- /dev/null +++ b/docs/source/types/vector.rst @@ -0,0 +1,11 @@ +.. _vector-search-record-types: + +************************* +Vector Search Record Type +************************* + + +VectorSearchRecord +================== + +.. autoclass:: neo4j_genai.types.VectorSearchRecord diff --git a/src/neo4j_genai/retrievers/hybrid.py b/src/neo4j_genai/retrievers/hybrid.py index 2ec4a3ec1..bc4d0ca82 100644 --- a/src/neo4j_genai/retrievers/hybrid.py +++ b/src/neo4j_genai/retrievers/hybrid.py @@ -127,9 +127,9 @@ def search( Args: query_text (str): The text to get the closest neighbors of. - query_vector (Optional[list[float]], optional): The vector embeddings to get the closest neighbors of. Defaults to None. - top_k (int, optional): The number of neighbors to return. Defaults to 5. - query_params (Optional[dict[str, Any]], optional): Parameters for the Cypher query. Defaults to None. + query_vector (Optional[list[float]]): The vector embeddings to get the closest neighbors of. Defaults to None. + top_k (int): The number of neighbors to return. Defaults to 5. + query_params (Optional[dict[str, Any]]): Parameters for the Cypher query. Defaults to None. Raises: ValueError: If validation of the input arguments fail. diff --git a/src/neo4j_genai/retrievers/vector.py b/src/neo4j_genai/retrievers/vector.py index 4d8678602..3156d8b01 100644 --- a/src/neo4j_genai/retrievers/vector.py +++ b/src/neo4j_genai/retrievers/vector.py @@ -32,6 +32,14 @@ class VectorRetriever(Retriever): """ Provides retrieval method using vector search over embeddings. If an embedder is provided, it needs to have the required Embedder type. + + Example: + + .. code-block:: python + + retriever = VectorRetriever(driver, "vector-index-name", custom_embedder) + retriever.search(query_text="Find me a book about Fremen", top_k=top_k) + """ def __init__( @@ -59,9 +67,9 @@ def search( - `db.index.vector.queryNodes() `_ Args: - query_vector (Optional[list[float]], optional): The vector embeddings to get the closest neighbors of. Defaults to None. - query_text (Optional[str], optional): The text to get the closest neighbors of. Defaults to None. - top_k (int, optional): The number of neighbors to return. Defaults to 5. + query_vector (Optional[list[float]]): The vector embeddings to get the closest neighbors of. Defaults to None. + query_text (Optional[str]): The text to get the closest neighbors of. Defaults to None. + top_k (int): The number of neighbors to return. Defaults to 5. Raises: ValueError: If validation of the input arguments fail. @@ -138,10 +146,10 @@ def search( - `db.index.vector.queryNodes() `_ Args: - query_vector (Optional[list[float]], optional): The vector embeddings to get the closest neighbors of. Defaults to None. - query_text (Optional[str], optional): The text to get the closest neighbors of. Defaults to None. - top_k (int, optional): The number of neighbors to return. Defaults to 5. - query_params (Optional[dict[str, Any]], optional): Parameters for the Cypher query. Defaults to None. + query_vector (Optional[list[float]]): The vector embeddings to get the closest neighbors of. Defaults to None. + query_text (Optional[str]): The text to get the closest neighbors of. Defaults to None. + top_k (int): The number of neighbors to return. Defaults to 5. + query_params (Optional[dict[str, Any]]): Parameters for the Cypher query. Defaults to None. Raises: ValueError: If validation of the input arguments fail. diff --git a/src/neo4j_genai/types.py b/src/neo4j_genai/types.py index 67a311752..87191506c 100644 --- a/src/neo4j_genai/types.py +++ b/src/neo4j_genai/types.py @@ -19,6 +19,14 @@ class VectorSearchRecord(BaseModel): + """ + Represents a record returned from a vector search. + + Attributes: + node (Any): The node data retrieved by the search. + score (float): The similarity score of the retrieved embedding. + """ + node: Any score: float