Skip to content

Conversation

anyxling
Copy link
Member

@anyxling anyxling commented Jul 26, 2025

Description

from langchain_arangodb import ArangoGraphQAChain
from arango import ArangoClient

# Connect to ArangoDB
db = ArangoClient().db(...)

# Initialize components
graph = ArangoGraph()
emb_model = OpenAIEmbeddings(model="text-embedding-3-large")  # Replace with your embedding model
llm = ChatOpenAI(model="gpt-4o", temperature=0)  # Replace with your LLM

# Create the chain
chain = ArangoGraphChain.from_llm(
    llm=llm,
    graph=graph,
    embedding=emb_model,
    query_cache_collection_name="Queries",
)

# Ask a question
query = "How old is Cersei Lannister?"  # Replace with your query
chain.invoke({
    "query": query, 
    "use_query_cache": True  # Optional: remove to force LLM-based AQL generation,
   "query_cache_similarity_threshold": 0.80  # default is 0.80 or replace with your desired value
}) 

As shown in the screenshot below, when the exact query exists in the cache, it is reused directly with a similarity score of 1.0.
Screenshot 2025-07-29 at 16 25 54

If we ask a semantically similar question like:

query = "What is the age of Cersei Lannister"
chain.invoke({"query": query, "use_query_cache": True})

The system will perform vector search and fetch the AQL query with the highest similarity score (0.92 in this case).
Screenshot 2025-07-29 at 16 30 59

If no cached query is greater than the threshold(0.80), LLM-based AQL generation will be invoked.
Screenshot 2025-07-29 at 16 47 05

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Project configuration change

Complexity

Note

Please provide an estimated complexity of this PR of either Low, Medium or High

How Has This Been Tested?

  • Unit tests
  • Integration tests
  • Manual tests

Checklist

  • Unit tests updated
  • Integration tests updated
  • CHANGELOG.md updated

@anyxling anyxling requested a review from aMahanna July 26, 2025 02:38
Copy link
Member

@aMahanna aMahanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! here's the 1st review round

Copy link
Member

@aMahanna aMahanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! thank you, feel free to merge

@anyxling anyxling merged commit 0907cfa into main Aug 11, 2025
9 checks passed
@aMahanna aMahanna deleted the monika-querycache branch August 11, 2025 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants