For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
PlaygroundDiscordStatusDashboardSign Up >
DocumentationSDK ReferenceGraphiti
DocumentationSDK ReferenceGraphiti
      • Chunking Large Documents
      • Check Data Ingestion Status
      • Give Your Agent Domain Knowledge
      • Share Context Across Users Using Graphs
      • Add User Specific Business Data to User Graphs
      • Get Most Relevant Facts for an Arbitrary Query
      • Find Facts Relevant to a Specific Node
LogoLogo
PlaygroundDiscordStatusDashboardSign Up >
Cookbook

Get Most Relevant Facts for an Arbitrary Query

Was this page helpful?
Previous

Find Facts Relevant to a Specific Node

Next
Built with

In this recipe, we demonstrate how to retrieve the most relevant facts from the knowledge graph using an arbitrary search query.

First, we perform a search on the knowledge graph using a sample query:

1from zep_cloud.client import Zep
2
3zep_client = Zep(api_key=API_KEY)
4results = zep_client.graph.search(user_id="some user_id", query="Some search query", scope="edges")

Then, we get the edges from the search results and construct our fact list. We also include the temporal validity data to each fact string:

1# Build list of formatted facts
2relevant_edges = results.edges
3formatted_facts = []
4for edge in relevant_edges:
5 valid_at = edge.valid_at if edge.valid_at is not None else "date unknown"
6 invalid_at = edge.invalid_at if edge.invalid_at is not None else "present"
7 formatted_fact = f"{edge.fact} (Date range: {valid_at} - {invalid_at})"
8 formatted_facts.append(formatted_fact)
9
10# Print the results
11print("\nFound facts:")
12for fact in formatted_facts:
13 print(f"- {fact}")

We demonstrated how to retrieve the most relevant facts for an arbitrary query using the Zep client. Adjust the query and parameters as needed to tailor the search for your specific use case.