Skip to navigation

Querying a Graph

Retrieve multi-hop context from a graph in one call

graph.query is experimental and available to every Zep account. The request, the response, the events, and the modes of the operation can change.

Some agent tasks need multi-hop retrieval. The agent does not know in advance what to search for. It must retrieve a record, learn from it, and then plan the next retrieval. Smart Query (graph.query) is the agentic retrieval API of Zep. In one call, Zep explores one graph with searches and graph traversals. It uses the records from each retrieval round to plan the next round. The operation is read-only.

The response contains at most 300 records in results. When the query returns more than 300 records, the server keeps cited records first in citation order. The server then keeps other records in the order that retrieval calls first returned them. The response sets truncated to true when the server omits records.

By default, the response has the records and no answer. When the request sets generate_answer to true, the response also includes an answer that a model writes from the records and citations to the graph items.

Select a mode

The mode field selects the retrieval mode. The default is fast.

ModeWhat the query does
fastOptimized for latency. Retrieves the context for multi-hop queries. The query runs at most 3 search rounds.
deepRuns more retrieval steps, so it can retrieve complete lists, such as the records for a count. It takes longer than fast.

A value other than fast or deep returns 400 invalid_request with param set to mode.

from zep_cloud import Zep
client = Zep(
api_key=API_KEY,
)
response = client.graph.query(
graph_uuids=[graph_uuid],
query="Which companies acquired a logistics company in 2024?",
mode="deep",
generate_answer=True,
)
print(response.answer)
for edge in response.results.edges:
print(edge.fact)

Check the answer status

When the request sets generate_answer to true, the response also has answer_status. Use this field to find a refusal. Do not compare the text of answer, because the model writes the answer in the language of the query or in the language that the guidance requests.

answer_statusMeaning
answeredThe answer covers the query.
partialThe answer covers only part of the query. The end of the answer says that the records do not answer the rest.
refusedThe records do not answer the query, or the query is not about the graph.

A response without an answer has no answer_status. When the status is partial or refused, results still contains the retrieved records. You can send the query again with mode set to deep, which can read more records.

response = client.graph.query(
graph_uuids=[graph_uuid],
query="Which weekly meetings discussed the budget in 2024?",
generate_answer=True,
)
if response.answer_status == "refused":
response = client.graph.query(
graph_uuids=[graph_uuid],
query="Which weekly meetings discussed the budget in 2024?",
mode="deep",
generate_answer=True,
)
print(response.answer_status, response.answer)

BYOM and BYOC

fast mode needs a decision model. A Zep-hosted project uses a Zep decision model. A BYOM project or a BYOC deployment must configure a decision model to use fast mode.

  • When a BYOM project has a decision model, fast mode uses that decision model. A BYOC deployment can use fast mode only when it has a BYOM configuration with a decision model, such as SystemOne or Gemini Decisions.
  • When a BYOM project or a BYOC deployment has no decision model, set mode to deep. All model calls of a deep query go to your BYOM provider. A fast request returns 400 invalid_request with param set to mode and the message “Fast mode requires a decision model when the project uses its own LLM provider. Add a decision model in LLM providers, or set mode to deep.”
  • When the BYOM configuration has no compatible model, a deep request returns 400 invalid_request.