You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow specifying database name for retrievers and index handling methods (#71)
* Include database name in driver.execute_query
* Update tests
* Added configurable database names to the Pinecone and Weaviate retrievers
* Fix typing for filtered vector queries (#76)
* Rename database to neo4j_database
---------
Co-authored-by: Jon Besga <jon.besga@neo4j.com>
Copy file name to clipboardExpand all lines: src/neo4j_genai/indexes.py
+19-6Lines changed: 19 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@
15
15
from __future__ importannotations
16
16
17
17
importlogging
18
-
fromtypingimportLiteral
18
+
fromtypingimportLiteral, Optional
19
19
20
20
importneo4j
21
21
frompydanticimportValidationError
@@ -33,6 +33,7 @@ def create_vector_index(
33
33
embedding_property: str,
34
34
dimensions: int,
35
35
similarity_fn: Literal["euclidean", "cosine"],
36
+
neo4j_database: Optional[str] =None,
36
37
) ->None:
37
38
"""
38
39
This method constructs a Cypher query and executes it
@@ -77,6 +78,7 @@ def create_vector_index(
77
78
dimensions (int): Vector embedding dimension
78
79
similarity_fn (str): case-insensitive values for the vector similarity function:
79
80
``euclidean`` or ``cosine``.
81
+
neo4j_database (Optional[str]): The name of the Neo4j database. If not provided, this defaults to "neo4j" in the database (`see reference to documentation <https://neo4j.com/docs/operations-manual/current/database-administration/#manage-databases-default>`_).
80
82
81
83
Raises:
82
84
ValueError: If validation of the input arguments fail.
This method constructs a Cypher query and executes it
@@ -151,6 +158,7 @@ def create_fulltext_index(
151
158
name (str): The unique name of the index.
152
159
label (str): The node label to be indexed.
153
160
node_properties (list[str]): The node properties to create the fulltext index on.
161
+
neo4j_database (Optional[str]): The name of the Neo4j database. If not provided, this defaults to "neo4j" in the database (`see reference to documentation <https://neo4j.com/docs/operations-manual/current/database-administration/#manage-databases-default>`_).
154
162
155
163
Raises:
156
164
ValueError: If validation of the input arguments fail.
neo4j_database (Optional[str]): The name of the Neo4j database. If not provided, this defaults to "neo4j" in the database (`see reference to documentation <https://neo4j.com/docs/operations-manual/current/database-administration/#manage-databases-default>`_).
213
224
214
225
Raises:
215
226
neo4j.exceptions.ClientError: If dropping of index fails.
raiseNeo4jIndexError(f"Dropping Neo4j index failed: {e.message}") frome
226
237
@@ -230,6 +241,7 @@ def upsert_vector(
230
241
node_id: int,
231
242
embedding_property: str,
232
243
vector: list[float],
244
+
neo4j_database: Optional[str] =None,
233
245
) ->None:
234
246
"""
235
247
This method constructs a Cypher query and executes it to upsert (insert or update) a vector property on a specific node.
@@ -260,6 +272,7 @@ def upsert_vector(
260
272
node_id (int): The id of the node.
261
273
embedding_property (str): The name of the property to store the vector in.
262
274
vector (list[float]): The vector to store.
275
+
neo4j_database (Optional[str]): The name of the Neo4j database. If not provided, this defaults to "neo4j" in the database (`see reference to documentation <https://neo4j.com/docs/operations-manual/current/database-administration/#manage-databases-default>`_).
263
276
264
277
Raises:
265
278
Neo4jInsertionError: If upserting of the vector fails.
Copy file name to clipboardExpand all lines: src/neo4j_genai/retrievers/external/pinecone/pinecone.py
+7-1Lines changed: 7 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -79,6 +79,7 @@ class PineconeNeo4jRetriever(ExternalRetriever):
79
79
embedder (Optional[Embedder]): Embedder object to embed query text.
80
80
return_properties (Optional[list[str]]): List of node properties to return.
81
81
result_formatter (Optional[Callable[[Any], Any]]): Function to transform a neo4j.Record to a RetrieverResultItem.
82
+
neo4j_database (Optional[str]): The name of the Neo4j database. If not provided, this defaults to "neo4j" in the database (`see reference to documentation <https://neo4j.com/docs/operations-manual/current/database-administration/#manage-databases-default>`_).
82
83
83
84
Raises:
84
85
RetrieverInitializationError: If validation of the input arguments fail.
Copy file name to clipboardExpand all lines: src/neo4j_genai/retrievers/external/weaviate/weaviate.py
+9-2Lines changed: 9 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -70,6 +70,7 @@ class WeaviateNeo4jRetriever(ExternalRetriever):
70
70
embedder (Optional[Embedder]): Embedder object to embed query text.
71
71
return_properties (Optional[list[str]]): List of node properties to return.
72
72
result_formatter (Optional[Callable[[Any], Any]]): Function to transform a neo4j.Record to a RetrieverResultItem.
73
+
neo4j_database (Optional[str]): The name of the Neo4j database. If not provided, this defaults to "neo4j" in the database (`see reference to documentation <https://neo4j.com/docs/operations-manual/current/database-administration/#manage-databases-default>`_).
73
74
74
75
Raises:
75
76
RetrieverInitializationError: If validation of the input arguments fail.
Copy file name to clipboardExpand all lines: src/neo4j_genai/retrievers/hybrid.py
+19-4Lines changed: 19 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -69,6 +69,8 @@ class HybridRetriever(Retriever):
69
69
fulltext_index_name (str): Fulltext index name.
70
70
embedder (Optional[Embedder]): Embedder object to embed query text.
71
71
return_properties (Optional[list[str]]): List of node properties to return.
72
+
neo4j_database (Optional[str]): The name of the Neo4j database. If not provided, this defaults to "neo4j" in the database (`see reference to documentation <https://neo4j.com/docs/operations-manual/current/database-administration/#manage-databases-default>`_).
@@ -212,6 +220,7 @@ class HybridCypherRetriever(Retriever):
212
220
retrieval_query (str): Cypher query that gets appended.
213
221
embedder (Optional[Embedder]): Embedder object to embed query text.
214
222
result_formatter (Optional[Callable[[Any], Any]]): Provided custom function to transform a neo4j.Record to a RetrieverResultItem.
223
+
neo4j_database (Optional[str]): The name of the Neo4j database. If not provided, this defaults to "neo4j" in the database (`see reference to documentation <https://neo4j.com/docs/operations-manual/current/database-administration/#manage-databases-default>`_).
215
224
216
225
Raises:
217
226
RetrieverInitializationError: If validation of the input arguments fail.
0 commit comments