|
1 | 1 | .. _user-guide-rag: |
2 | 2 |
|
3 | 3 | User Guide: RAG |
4 | | -################# |
| 4 | +############### |
5 | 5 |
|
6 | 6 | This guide provides a starting point for using the Neo4j GraphRAG package |
7 | 7 | and configuring it according to specific requirements. |
8 | 8 |
|
9 | 9 |
|
10 | | -************ |
| 10 | +********** |
11 | 11 | Quickstart |
12 | | -************ |
| 12 | +********** |
13 | 13 |
|
14 | 14 | To perform a GraphRAG query using the `neo4j-graphrag` package, a few components are needed: |
15 | 15 |
|
@@ -63,9 +63,9 @@ In practice, it's done with only a few lines of code: |
63 | 63 |
|
64 | 64 | The following sections provide more details about how to customize this code. |
65 | 65 |
|
66 | | -****************************** |
| 66 | +********************** |
67 | 67 | GraphRAG Configuration |
68 | | -****************************** |
| 68 | +********************** |
69 | 69 |
|
70 | 70 | Each component can be configured individually: the LLM and the prompt. |
71 | 71 |
|
@@ -775,7 +775,7 @@ See :ref:`hybridcypherretriever`. |
775 | 775 | .. _text2cypher-retriever-user-guide: |
776 | 776 |
|
777 | 777 | Text2Cypher Retriever |
778 | | ------------------------------------- |
| 778 | +--------------------- |
779 | 779 |
|
780 | 780 | This retriever first asks an LLM to generate a Cypher query to fetch the exact |
781 | 781 | information required to answer the question from the database. Then this query is |
@@ -853,7 +853,7 @@ See :ref:`text2cypherretriever`. |
853 | 853 | .. _custom-retriever: |
854 | 854 |
|
855 | 855 | Custom Retriever |
856 | | -=================== |
| 856 | +================ |
857 | 857 |
|
858 | 858 | If the application requires very specific retrieval strategy, it is possible to implement |
859 | 859 | a custom retriever using the `Retriever` interface: |
@@ -883,14 +883,60 @@ a custom retriever using the `Retriever` interface: |
883 | 883 | See :ref:`rawsearchresult` for a description of the returned type. |
884 | 884 |
|
885 | 885 |
|
886 | | -****************************** |
| 886 | +*********************** |
| 887 | +GraphRAG search options |
| 888 | +*********************** |
| 889 | + |
| 890 | +Return context |
| 891 | +============== |
| 892 | + |
| 893 | +By default, the search method only returns the final answer. It is possible to see |
| 894 | +what was retrieved as part of the context by setting `return_context=True`: |
| 895 | + |
| 896 | +.. code:: python |
| 897 | +
|
| 898 | + rag.search("my question", return_context=True) |
| 899 | +
|
| 900 | +
|
| 901 | +Return a custom message if context is empty |
| 902 | +=========================================== |
| 903 | + |
| 904 | +If the retriever is not able to find any context, the LLM will return an answer anyway. |
| 905 | +It is possible to skip the LLM call if the context is empty and return a user-defined message |
| 906 | +instead: |
| 907 | + |
| 908 | +.. code:: python |
| 909 | +
|
| 910 | + rag.search( |
| 911 | + "my question", |
| 912 | + response_fallback="I can not answer this question because I have no relevant context." |
| 913 | + ) |
| 914 | +
|
| 915 | +
|
| 916 | +Pass configuration to the retriever search method |
| 917 | +================================================= |
| 918 | + |
| 919 | +The retrievers search method have a bunch of configuration options (see above), |
| 920 | +which can also be configured through the GraphRAG search method using the `retriever_config` |
| 921 | +argument. For instance, the following code snippet illustrates how to define the `top_k` |
| 922 | +parameter for the retriever: |
| 923 | + |
| 924 | +.. code:: python |
| 925 | +
|
| 926 | + rag.search( |
| 927 | + "my question", |
| 928 | + retriever_config={"top_k": 2} |
| 929 | + ) |
| 930 | +
|
| 931 | +
|
| 932 | +************** |
887 | 933 | DB Operations |
888 | | -****************************** |
| 934 | +************** |
889 | 935 |
|
890 | 936 | See :ref:`database-interaction-section`. |
891 | 937 |
|
892 | 938 | Create a Vector Index |
893 | | -======================== |
| 939 | +===================== |
894 | 940 |
|
895 | 941 | .. code:: python |
896 | 942 |
|
@@ -918,7 +964,7 @@ Create a Vector Index |
918 | 964 |
|
919 | 965 |
|
920 | 966 | Populate a Vector Index |
921 | | -========================== |
| 967 | +======================= |
922 | 968 |
|
923 | 969 | .. code:: python |
924 | 970 |
|
@@ -950,7 +996,7 @@ This property will also be added to the vector index. |
950 | 996 |
|
951 | 997 |
|
952 | 998 | Drop a Vector Index |
953 | | -======================== |
| 999 | +=================== |
954 | 1000 |
|
955 | 1001 | .. warning:: |
956 | 1002 |
|
|
0 commit comments