From 6f6fb3f3d126380c41d323a4a2754bf76bbcc04f Mon Sep 17 00:00:00 2001 From: MonikaLiu Date: Mon, 18 Aug 2025 10:23:55 -0700 Subject: [PATCH 1/5] add schema_include_views in generate_schema --- libs/arangodb/doc/graph.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/arangodb/doc/graph.rst b/libs/arangodb/doc/graph.rst index cffd278..509fdab 100644 --- a/libs/arangodb/doc/graph.rst +++ b/libs/arangodb/doc/graph.rst @@ -198,7 +198,8 @@ Generates a schema representation of the database. sample_ratio=0.1, graph_name="MyGraph", include_examples=True, - list_limit=32 + list_limit=32, + schema_include_views=True ) set_schema @@ -450,7 +451,8 @@ Here's a complete example demonstrating a typical workflow using ArangoGraph to schema = graph.generate_schema( sample_ratio=1.0, # Use all documents for schema graph_name="CompanyGraph", - include_examples=True + include_examples=True, + schema_include_views=True ) print("Schema:", schema) From a592a731cddce9718b9f994b067b8e6380afbbb2 Mon Sep 17 00:00:00 2001 From: MonikaLiu Date: Mon, 18 Aug 2025 15:05:18 -0700 Subject: [PATCH 2/5] add chat history & query cache --- libs/arangodb/.coverage | Bin 53248 -> 53248 bytes libs/arangodb/doc/arangoqachain.rst | 114 ++++++++++++++++++++++++++-- 2 files changed, 106 insertions(+), 8 deletions(-) diff --git a/libs/arangodb/.coverage b/libs/arangodb/.coverage index 6be0db14556019b6164ad34f92c07fc5a1e33299..f8c9855d2b3fb854ce194d833a8a8ff8b88210da 100644 GIT binary patch literal 53248 zcmeI4e{2)y8OPuAoqaz4dW`}zG(|aybs;5*3ENa)8-W%yp;pSe(GH2V=ImUO1KStw z&LKftgWa`AOtjS|P1}S98WA30evX-t*p% z*apHXRoIk0r}%yE?)`D!=kq@A``&Bk?rV=eqFJikryDuNl0Qr0gyYC^Stf)?@QK35 z+eFwAyaR~2s{QG9CDJ+cohW^rL;^bqeKOiZJ0d%yp9vp}m!CupwXlmlN zskTjuk%7N(jWuwhV#?}1s3@Zwy-a=DQ1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f3#eeox541QpoJ&z#BaW&c6e+r1naC zqMg>-v{v;`^j{xV2h|?+gz~p?2MPY8V*b(v<1lrzINdjNX}fjq{?d5w^vHVu^R?fN z0=&LYX)_URe|dm6&Ess3mGn%Zm|C2sz&{iK>20rPuvFg?aF&jqc47*xuRJTucHK%^ zGgY&%yjv~n;MlnJF{^6rjDv}>7nX11(|0{|YMwvdOM`Mpf9LUzjWEwcaWYE@s!Tg2 z6ur_KW~T7pGebAZ0B~FwgD7`W050N042rZUpjaS`cID*ovK>8tVV{)UOa)VH6!SJp z=y3CGHxmGO060>Jo0-?U7Zq=|fk`WlQvh1We%D?-oS1&_^5~v@ZO02ut9xCX!`(SL z--hBcTOQ`xbI~RXXmi)FsI#$vJz#axGDyF-JXC`3AH44dVEk|&2u+=DA6ea-2d{le zof;Wm#U+2= 0.80 (default: 0.80) + ) + + query1 = "Who directed The Matrix?" + response1 = chain.invoke({"query": query1, "use_query_cache": False}) # Disable query cache to force fresh LLM generation + print(response1["result"]) + + # Cache the query and its result if you are satisfied + chain.cache_query() # Caches the most recent query by default + + # Alternatively, you can cache a query-AQL pair manually + chain.cache_query( + text="Who directed The Matrix?", + aql="FOR m IN Movies FILTER m.title == 'The Matrix' RETURN m.director" + ) + + # Similar query: uses exact match or vector similarity to fetch a cached AQL query and its result + query2 = "Who is the director of The Matrix?" + response2 = chain.invoke({ + "query": query2, + "query_cache_similarity_threshold": 0.90}) # Adjust threshold if needed + print(response2["result"]) + + # Clear all cached queries + chain.clear_query_cache() + + # Or, clear a specific cached query + chain.clear_query_cache(text="Who directed The Matrix?") + +9. Chat History +~~~~~~~~~~~~~~~ + +Enable context-aware responses by including chat history: + +.. code-block:: python + + # Initialize chat message history (required for chat history) + history = ArangoChatMessageHistory( + session_id="user_123", + db=db, + collection_name="chat_sessions" + ) + + chain = ArangoGraphQAChain.from_llm( + llm=llm, + graph=graph, + allow_dangerous_requests=True, + include_history=True, # Enables chat history (default: False) + chat_history_store=history, # Instance of ArangoChatMessageHistory. Required if include_history is True + max_history_messages=10 # Optional: maximum number of messages to include (default: 10) + ) + + query = "What movies were released in 1999?" + response = chain.invoke({"query": query, "include_history": False}) # Disable chat history + print(response["result"]) + + query = "Among all those movies, which one is directed by Lana Wachowski?" + response = chain.invoke({"query": query}) # include_history already set to True in the chain, enabling the LLM to understand what "those movies" refer to + print(response["result"]) + + Complete Workflow Example ------------------------- @@ -161,9 +238,8 @@ Here's a complete workflow showing how to use multiple features together: .. code-block:: python - from langchain_arangodb.chains.graph_qa.arangodb import ArangoGraphQAChain - from langchain_arangodb.graphs.arangodb_graph import ArangoGraph - from langchain.chat_models import ChatOpenAI + from langchain_arangodb import ArangoGraphQAChain, ArangoGraph, ArangoChatMessageHistory + from langchain_openai import ChatOpenAI, OpenAIEmbeddings from arango import ArangoClient # 1. Setup Database Connection @@ -194,6 +270,18 @@ Here's a complete workflow showing how to use multiple features together: # 5. Initialize Chain with Advanced Features llm = ChatOpenAI(temperature=0) + + # 6. Initialize Embedding Model (required for query cache) + embedding = OpenAIEmbeddings(model="text-embedding-3-large") + + # 7. Initialize chat message history (required for chat history) + history = ArangoChatMessageHistory( + session_id="user_123", + db=db, + collection_name="chat_sessions" + ) + + # 8. Initialize Chain with Advanced Features chain = ArangoGraphQAChain.from_llm( llm=llm, graph=graph, @@ -203,12 +291,21 @@ Here's a complete workflow showing how to use multiple features together: return_aql_query=True, return_aql_result=True, output_list_limit=20, - output_string_limit=200 + output_string_limit=200, + use_query_cache=True, + embedding=embedding, + query_cache_collection_name="Queries", + query_cache_similarity_threshold=0.80, + include_history=True, + chat_history_store=history, + max_history_messages=10 ) - # 6. Run Multiple Queries + # 9. Run Multiple Queries queries = [ "Who acted in The Matrix?", + "Who starred in The Matrix?", + "What is the last name of this actor?" "What movies were released in 1999?", "List all actors in the database" ] @@ -220,6 +317,7 @@ Here's a complete workflow showing how to use multiple features together: print("AQL Query:", response["aql_query"]) print("Raw Results:", response["aql_result"]) print("Final Answer:", response["result"]) + chain.cache_query() print("-" * 50) Security Considerations From c469169239dc9b0b92737681696ee6387b986d00 Mon Sep 17 00:00:00 2001 From: MonikaLiu Date: Mon, 18 Aug 2025 15:26:09 -0700 Subject: [PATCH 3/5] remove .coverage commit --- libs/arangodb/.coverage | Bin 53248 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 libs/arangodb/.coverage diff --git a/libs/arangodb/.coverage b/libs/arangodb/.coverage deleted file mode 100644 index f8c9855d2b3fb854ce194d833a8a8ff8b88210da..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 53248 zcmeI4e{2)y8OPuAoqaz4dW`}zG(|aybs;5*3ENa)8-W%yp;pSe(GH2V=ImUO1KStw z&LKftgWa`AOtjS|P1}S98WA30evX-t*p% z*apHXRoIk0r}%yE?)`D!=kq@A``&Bk?rV=eqFJikryDuNl0Qr0gyYC^Stf)?@QK35 z+eFwAyaR~2s{QG9CDJ+cohW^rL;^bqeKOiZJ0d%yp9vp}m!CupwXlmlN zskTjuk%7N(jWuwhV#?}1s3@Zwy-a=DQ1Y1p)ohoQDGM_?=p42jYYjb@v~)SEbH0#E1M&@p+#qWlDB)b#(x)pqU0F+ajs3`NbCb5L*jv+_9&*;APN_m(+f-1e z8oynxlx(-n$m{JgGXgx|zHlJ1q=_TomFlp$DGT>oDWzcP_HhatKh*_6sN2+m}sngTA4ojcjZ&)v>brRN#vRPU0v%3r{Ejx_^-dx>hk{%4j zU>!}?-Hf2Lq29*Cf(ALA)zh`UW_ygOLI;7dz{}QG$Y)qrF_{e+eMmKweznt0b%upT zI}*4~mlQ~>YMIV;rd%M^HMJWm&IyQ#=4P%W*>2>vmK%vRF66c3O@>h~DW@uC!SDu> zTMd$4iOMMH^$|A(%;^vVi51P$nd9b5b-6piq9}-oS+lsJ(<9ip#6JESBiNZr7r1UB z_~`Nn6>C7gQ9C;g!dv};#202wC!9%0b+It;^g5p{dD|SDehvnG_Tg(JvojUR533^` zLrNA#lR-r@pv%G-?92c%%h;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;ATw~{KTStEMrXco z;@R){Rvvnne0TQFSIOwwxsXJ*nmdpFP5g4-)qn2z&Cw;h4jvyrvbp*48-IQ2RATh4 zz<%;XfM?g{xqy$wJ}$rsk`&*vhyDH^qq_;cN-xrL^k4KHdV(IKuhZYrU(rxv*- Date: Tue, 19 Aug 2025 20:35:24 -0700 Subject: [PATCH 4/5] update comment Co-authored-by: Anthony Mahanna <43019056+aMahanna@users.noreply.github.com> --- libs/arangodb/doc/arangoqachain.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/arangodb/doc/arangoqachain.rst b/libs/arangodb/doc/arangoqachain.rst index 336fab8..8e2ba5f 100644 --- a/libs/arangodb/doc/arangoqachain.rst +++ b/libs/arangodb/doc/arangoqachain.rst @@ -223,7 +223,7 @@ Enable context-aware responses by including chat history: ) query = "What movies were released in 1999?" - response = chain.invoke({"query": query, "include_history": False}) # Disable chat history + response = chain.invoke({"query": query, "include_history": False}) # Disable chat history (on function call only) print(response["result"]) query = "Among all those movies, which one is directed by Lana Wachowski?" From fabde9c442dde0af19f9a0c86108706ef0c6e42c Mon Sep 17 00:00:00 2001 From: MonikaLiu Date: Wed, 20 Aug 2025 11:53:21 -0700 Subject: [PATCH 5/5] adjust indentation --- libs/arangodb/doc/arangoqachain.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/arangodb/doc/arangoqachain.rst b/libs/arangodb/doc/arangoqachain.rst index 8e2ba5f..e8943a3 100644 --- a/libs/arangodb/doc/arangoqachain.rst +++ b/libs/arangodb/doc/arangoqachain.rst @@ -190,7 +190,8 @@ Enable query caching to reuse past queries, reducing response time and LLM cost: query2 = "Who is the director of The Matrix?" response2 = chain.invoke({ "query": query2, - "query_cache_similarity_threshold": 0.90}) # Adjust threshold if needed + "query_cache_similarity_threshold": 0.90 + }) # Adjust threshold if needed print(response2["result"]) # Clear all cached queries