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
Copy file name to clipboardExpand all lines: docs/source/user_guide_rag.rst
+20-12Lines changed: 20 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -543,11 +543,11 @@ See also :ref:`vectorretriever`.
543
543
Vector Cypher Retriever
544
544
=======================
545
545
546
-
The `VectorCypherRetriever` allows full utilization of Neo4j's graph nature by
547
-
enhancing context through graph traversal.
546
+
The `VectorCypherRetriever` fully leverages Neo4j's graph capabilities by combining vector-based similarity searches with graph traversal techniques. It processes a query embedding to perform a similarity search against a specified vector index, retrieves relevant node variables, and then executes a Cypher query to traverse the graph based on these nodes. This integration ensures that retrievals are both semantically meaningful and contextually enriched by the underlying graph structure.
547
+
548
548
549
549
Retrieval Query
550
-
-----------------------------
550
+
---------------
551
551
552
552
When crafting the retrieval query, it's important to note two available variables
553
553
are in the query scope:
@@ -560,26 +560,34 @@ certain movie properties, the retrieval query can be structured as follows:
560
560
561
561
.. code:: python
562
562
563
+
retrieval_query ="""
564
+
MATCH
565
+
(actor:Actor)-[:ACTED_IN]->(node)
566
+
RETURN
567
+
node.title AS movie_title,
568
+
node.plot AS movie_plot,
569
+
collect(actor.name) AS actors;
570
+
"""
563
571
retriever = VectorCypherRetriever(
564
572
driver,
565
573
index_name=INDEX_NAME,
566
-
retrieval_query="MATCH (node)<-[:ACTED_IN]-(p:Person) RETURN node.title as movieTitle, node.plot as movieDescription, collect(p.name) as actors, score",
574
+
retrieval_query=retrieval_query,
567
575
)
568
576
569
577
578
+
It is recommended that the retrieval query returns node properties, as opposed to nodes.
579
+
580
+
570
581
Format the Results
571
-
-----------------------------
582
+
------------------
572
583
573
584
.. warning::
574
585
575
586
This API is in beta mode and will be subject to change in the future.
576
587
577
-
For improved readability and ease in prompt-engineering, formatting the result to suit
578
-
specific needs involves providing a `record_formatter` function to the Cypher retrievers.
579
-
This function processes the Neo4j record from the retrieval query, returning a
580
-
`RetrieverResultItem` with `content` (str) and `metadata` (dict) fields. The `content`
581
-
field is used for passing data to the LLM, while `metadata` can serve debugging purposes
582
-
and provide additional context.
588
+
The result_formatter function customizes the output of Cypher retrievers for improved prompt engineering and readability. It converts each Neo4j record into a RetrieverResultItem with two fields: `content` and `metadata`.
589
+
590
+
The `content` field is a formatted string containing the key information intended for the language model, such as movie titles or descriptions. The `metadata` field holds additional details, useful for debugging or providing extra context, like scores or node properties.
583
591
584
592
585
593
.. code:: python
@@ -738,7 +746,7 @@ Also note that there is an helper function to create a full-text index (see `the
738
746
.. _hybrid-cypher-retriever-user-guide:
739
747
740
748
Hybrid Cypher Retrievers
741
-
------------------------------------
749
+
------------------------
742
750
743
751
In an hybrid cypher retriever, results are searched for in both a vector and a
744
752
full-text index. Once the similar nodes are identified, a retrieval query can traverse
Copy file name to clipboardExpand all lines: src/neo4j_graphrag/retrievers/vector.py
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -220,6 +220,8 @@ class VectorCypherRetriever(Retriever):
220
220
221
221
Note: `node` is a variable from the base query that can be used in `retrieval_query` as seen in the example below.
222
222
223
+
The retrieval_query is additional Cypher that can allow for graph traversal after retrieving `node`.
224
+
223
225
Example:
224
226
225
227
.. code-block:: python
@@ -243,6 +245,7 @@ class VectorCypherRetriever(Retriever):
243
245
result_formatter (Optional[Callable[[neo4j.Record], RetrieverResultItem]]): Provided custom function to transform a neo4j.Record to a RetrieverResultItem.
244
246
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>`_).
245
247
248
+
Read more in the :ref:`User Guide <vector-cypher-retriever-user-guide>`.
0 commit comments