Skip to content

Commit 4220deb

Browse files
willtaioskarhanealexthomas93
authored
Update all docstrings and exceptions to be used for documentation (neo4j#55)
* Update docstrings, exceptions * Update src/neo4j_genai/retrievers/external/weaviate/weaviate.py Co-authored-by: Oskar Hane <oh@oskarhane.com> * Update src/neo4j_genai/retrievers/external/weaviate/weaviate.py Co-authored-by: Oskar Hane <oh@oskarhane.com> * Fixed tests * Included check whether e.message attribute exists * Add external vector index support for Pinecone (neo4j#52) * Added pinecone-client to poetry * Copied weaviate populate_dbs.py to pinecone_e2e * Updated tests/e2e/pinecone_e2e/populate_dbs.py to work with Pinecone * Copied the Weaviate retriever to use as a base for the Pinecone retriever * Added first draft of PineconeNeo4jRetriever * Added input validation to PineconeNeo4jRetriever * Renamed PineconeModel to PineconeClientModel * Added Pinecone retriever unit tests * Added E2E tests for pinecone retriever * Updated pinecone retriever to work with new return types * Updated E2E tests to work with new types * Added __init__.py to E2E tests * Update src/neo4j_genai/retrievers/external/pinecone/pinecone.py Co-authored-by: willtai <william.tai@neo4j.com> * Updated Pinecone retriever with new Exceptions * Added Pinecone example scripts * Moved Pinecone Pydantic types to their own file * Ran import organizer on examples/weaviate/text_search_local_embedder.py * Added docs for PineconeNeo4jRetriever * Pinecone E2E test fix * Pinecone E2E test update * Pincone E2E test fix * Moved populate_neo4j to its own file * Moved populate_neo4j to utils * Updated PineconeNeo4jRetriever import in test_pinecone_e2e.py * Removed copyright from Pinecone and Weaviate examples * Refactored E2E test utils * Small fix to tests/e2e/utils.py * Ran poetry lock --no-update * Small formatting changes * More formatting changes * Moved embedding_biology.py to the examples folder * mypy fixes * Removed unused imports * More mypy fixes * More mypy fixes * Added .venv to .gitignore * Fixed mypy pytest conflict --------- Co-authored-by: willtai <william.tai@neo4j.com> * Update docs build * Ruff formatting * Exclude docs in mypy check * Docstring for format_record_function in retrievers * Updated Text2CypherRetrievalError --------- Co-authored-by: Oskar Hane <oh@oskarhane.com> Co-authored-by: Alex Thomas <alexthomas93@users.noreply.github.com>
1 parent 7c30250 commit 4220deb

File tree

15 files changed

+204
-42
lines changed

15 files changed

+204
-42
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,14 @@ When you're finished with your changes, create a pull request, also known as a P
159159
the UI, and any other changes can be made in your fork and committed to the PR branch.
160160
- As you update your PR and apply changes, mark each conversation as [resolved](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/commenting-on-a-pull-request#resolving-conversations).
161161
- Update the `CHANGELOG.md` if you have made significant changes to the project, these include:
162-
- Major changes:
163-
- New features
164-
- Bug fixes with high impact
165-
- Breaking changes
166-
- Minor changes:
167-
- Documentation improvements
168-
- Code refactoring without functional impact
169-
- Minor bug fixes
162+
- Major changes:
163+
- New features
164+
- Bug fixes with high impact
165+
- Breaking changes
166+
- Minor changes:
167+
- Documentation improvements
168+
- Code refactoring without functional impact
169+
- Minor bug fixes
170170
- Keep `CHANGELOG.md` changes brief and focus on the most important changes.
171171

172172
### Updating the `CHANGELOG.md`

docs/source/_templates/gentree.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{%- extends "layout.html" %}
2+
{% set title = _('Tree') %}
3+
4+
{% block body %}
5+
<h1>{{ _('Tree') }}</h1>
6+
{{ toctree(includehidden=True, collapse=False, maxdepth=-1) }}
7+
{% endblock %}

docs/source/_templates/indexnav.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<div id="indexlinkbox">
2+
<h3 id="indexlinklabel">{{ _('Index') }}</h3>
3+
4+
<div class="indexlinkwrapper nav-menu">
5+
<ul>
6+
<li class="toctree-l1">
7+
<a href="{{ pathto('genindex')|e }}" class="indexlink genindex">
8+
{{ _('Alphabetical') }}
9+
</a>
10+
</li>
11+
<li class="toctree-l1">
12+
<a href="{{ pathto('gentree')|e }}" class="indexlink gentree">
13+
{{ _('Tree') }}
14+
</a>
15+
</li>
16+
</ul>
17+
</div>
18+
</div>

docs/source/api.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ Errors
8585

8686
* :class:`neo4j_genai.exceptions.Neo4jVersionError`
8787

88+
* :class:`neo4j_genai.exceptions.Text2CypherRetrievalError`
89+
90+
* :class:`neo4j_genai.exceptions.SchemaFetchError`
91+
8892

8993
Neo4jGenAiError
9094
===============
@@ -140,3 +144,17 @@ Neo4jVersionError
140144

141145
.. autoclass:: neo4j_genai.exceptions.Neo4jVersionError
142146
:show-inheritance:
147+
148+
149+
Text2CypherRetrievalError
150+
==========================
151+
152+
.. autoclass:: neo4j_genai.exceptions.Text2CypherRetrievalError
153+
:show-inheritance:
154+
155+
156+
SchemaFetchError
157+
================
158+
159+
.. autoclass:: neo4j_genai.exceptions.SchemaFetchError
160+
:show-inheritance:

docs/source/conf.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@
6868
html_theme = "neo4j"
6969
html_theme_path = ["themes"]
7070

71+
72+
# 01-nav.js is a copy of a js file of the same name that is included in the
73+
# docs-ui bundle
74+
def setup(app):
75+
app.add_js_file("https://neo4j.com/docs/assets/js/site.js", loading_method="defer")
76+
app.add_js_file("js/12-fragment-jumper.js", loading_method="defer")
77+
78+
79+
# Additional templates that should be rendered to pages, maps page names to
80+
# template names.
81+
html_additional_pages = {"gentree": "gentree.html"}
82+
7183
# The name of the Pygments (syntax highlighting) style to use.
7284
# pygments_style = "sphinx"
7385
pygments_style = "friendly"

docs/source/themes/neo4j/layout.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<header class="header">
1919
<nav class="navbar">
2020
<div class="navbar-brand">
21-
<a class="navbar-item" href="/docs/source/themes/themes/neo4j/static">
21+
<a class="navbar-item" href="https://neo4j.com/">
2222
<img class="navbar-logo" src="https://dist.neo4j.com/wp-content/uploads/20210422142941/neo4j-logo-2020.svg" alt="Neo4j Logo">
2323
</a>
2424
<a href="{{ pathto(root_doc)|e }}" class="navbar-item no-left-padding" aria-label="{{ html_title }}">

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ strict = true
7575
ignore_missing_imports = true
7676
allow_subclassing_any = true
7777
disallow_untyped_calls = false
78+
exclude = ["docs"]
7879

7980
[[tool.mypy.overrides]]
8081
module = [

src/neo4j_genai/exceptions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,15 @@ class Neo4jVersionError(Neo4jGenAiError):
6666

6767
def __init__(self) -> None:
6868
super().__init__("This package only supports Neo4j version 5.18.1 or greater")
69+
70+
71+
class Text2CypherRetrievalError(Neo4jGenAiError):
72+
"""Exception raised when text-to-cypher retrieval fails."""
73+
74+
pass
75+
76+
77+
class SchemaFetchError(Neo4jGenAiError):
78+
"""Exception raised when a Neo4jSchema cannot be fetched."""
79+
80+
pass

src/neo4j_genai/retrievers/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def _get_search_results(self, *args: Any, **kwargs: Any) -> RawSearchResult:
9797

9898
def get_result_formatter(self) -> Callable[[neo4j.Record], RetrieverResultItem]:
9999
"""
100-
Returns the function to use to transform a neo4j.Record to aRetrieverResultItem.
100+
Returns the function to use to transform a neo4j.Record to a RetrieverResultItem.
101101
"""
102102
if hasattr(self, "format_record_function"):
103103
return self.format_record_function or self.default_format_record

src/neo4j_genai/retrievers/external/pinecone/pinecone.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,46 @@
4343

4444

4545
class PineconeNeo4jRetriever(ExternalRetriever):
46+
"""
47+
Provides retrieval method using vector search over embeddings with a Pinecone database.
48+
If an embedder is provided, it needs to have the required Embedder type.
49+
50+
Example:
51+
52+
.. code-block:: python
53+
54+
from neo4j import GraphDatabase
55+
from neo4j_genai import PineconeNeo4jRetriever
56+
from pinecone import Pinecone
57+
58+
with GraphDatabase.driver(NEO4J_URL, auth=NEO4J_AUTH) as neo4j_driver:
59+
pc_client = Pinecone(PC_API_KEY)
60+
embedder = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
61+
62+
retriever = PineconeNeo4jRetriever(
63+
driver=neo4j_driver,
64+
client=pc_client,
65+
index_name="jeopardy",
66+
id_property_neo4j="id",
67+
embedder=embedder, # type: ignore
68+
)
69+
70+
result = retriever.search(query_text="biology", top_k=2)
71+
72+
Args:
73+
driver (neo4j.Driver): The Neo4j Python driver.
74+
client (Pinecone): The Pinecone client object.
75+
collection (str): Name of a set of Weaviate objects that share the same data structure.
76+
id_property_external (str): The name of the Weaviate property that has the identifier that refers to a corresponding Neo4j node id property.
77+
id_property_neo4j (str): The name of the Neo4j node property that's used as the identifier for relating matches from Weaviate to Neo4j nodes.
78+
embedder (Optional[Embedder]): Embedder object to embed query text.
79+
return_properties (Optional[list[str]]): List of node properties to return.
80+
format_record_function (Optional[Callable[[Any], Any]]): Function to transform a neo4j.Record to a RetrieverResultItem.
81+
82+
Raises:
83+
RetrieverInitializationError: If validation of the input arguments fail.
84+
"""
85+
4686
def __init__(
4787
self,
4888
driver: neo4j.Driver,
@@ -113,7 +153,7 @@ def _get_search_results(
113153
.. code-block:: python
114154
115155
from neo4j import GraphDatabase
116-
from neo4j_genai.retrievers.external.pinecone import PineconeNeo4jRetriever
156+
from neo4j_genai import PineconeNeo4jRetriever
117157
from pinecone import Pinecone
118158
119159
with GraphDatabase.driver(NEO4J_URL, auth=NEO4J_AUTH) as neo4j_driver:
@@ -124,7 +164,7 @@ def _get_search_results(
124164
index_name="jeopardy",
125165
id_property_neo4j="id"
126166
)
127-
embedding = ...
167+
biology_embedding = ...
128168
retriever.search(query_vector=biology_embedding, top_k=2)
129169
130170

0 commit comments

Comments
 (0)