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
  • Getting Started
    • Coding with LLMs
    • Key Concepts
    • Quickstart
    • Building an Agent Walkthrough
    • Memory
    • Projects
    • Users
    • Sessions
    • Groups
  • Working with the Graph
    • Understanding the Graph
    • Utilizing Facts and Summaries
    • Customizing Graph Structure
    • Adding Data to the Graph
    • Reading Data from the Graph
    • Searching the Graph
    • Deleting Data from the Graph
    • Debugging
  • Cookbook
    • Check Data Ingestion Status
    • Customize Your Memory Context String
    • Add User Specific Business Data to User Graphs
    • Share Memory Across Users Using Group Graphs
    • Get Most Relevant Facts for an Arbitrary Query
    • Find Facts Relevant to a Specific Node
  • Best Practices
    • Performance Best Practices
    • Adding JSON Best Practices
  • Ecosystem
    • LangGraph
    • Autogen
  • Migrations
    • February 2026 Deprecation Wave
    • Migrate from Mem0
  • FAQ
    • Frequently Asked Questions
  • Legal
    • Privacy Policy
    • Terms of Service
    • Website Terms of Use
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:

1zep_client = AsyncZep(api_key=API_KEY)
2results = await 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.