Some agent tasks need multi-hop retrieval. The agent retrieves one record, learns from it, and then decides what to retrieve next. Smart Query plans and runs these retrievals in one API call.
· 6 min read
Preston Rasmussen Until now, Zep's retrieval has been single-shot. You search one record type, or you get context across all record types in one call. Single-shot retrieval is fast, and it works well for many retrieval tasks.
Some agent tasks need context that one search can't retrieve. The agent knows what context it needs, but it does not know which records hold that context or how to get to them. It has to retrieve one record, learn from it, and then plan what to retrieve next. Retrieval of this type is multi-hop retrieval. Single-shot retrieval is weak on multi-hop retrieval.
Smart Query is Zep's agentic retrieval API, graph.query. It explores your graph and plans each retrieval from what the previous retrievals returned. Zep returns the graph records that it retrieved, and it can also write an answer from them. You don't have to build this search logic into every agent.
Multi-hop retrieval #
In multi-hop retrieval, each retrieval depends on what the previous retrieval returned. The agent can't write all of its searches at the start. The agent learns what to retrieve next from the records that it already has. The agent must explore the graph and plan each retrieval.
An example from the graph in the video: which weekly meetings covered workload and prioritization in February? To answer that, the agent first finds the agenda email, learns which meeting the email describes, and then retrieves that meeting and its date.
Some tasks also need a complete list or a count, for example every meeting that one person attended. A count is correct only when the retrieval finds every matching record.
An agent with search tools can run this retrieval itself. Each agent then needs its own retrieval logic: which search to run, what to retrieve next, and when to stop. Each new agent must implement and tune this logic again. Smart Query runs this logic in Zep.
How a query works #
graph.query takes a natural-language query and the UUID of one graph. The graph can be a standard graph or a user graph. The operation is read-only, and it does not keep conversation state. Each request is one query.
Zep returns the records grouped by type: edges (facts), nodes (entities), episodes, observations, and thread summaries. The response contains every distinct record that a successful retrieval call returned. The response includes records that the answer does not cite. The response holds at most 300 records. When Zep must omit records, it keeps the cited records first and sets truncated to true.
When you set generate_answer to true, Zep also writes an answer from the records. Each citation in the answer resolves to the UUID of a graph item, so your application can show the source of each statement. When you do not set it, the response has only the records, and your agent can write its own answer.
You can also add guidance, for example the rules of your domain or the format that you want for the answer. To see each retrieval call as it runs, set stream to true. Zep then streams the response as server-sent events. In the Python SDK, call graph.query_stream.
Fast mode and Deep mode #
The mode field selects the retrieval loop. The default is fast.
| Mode | How it retrieves | What it does |
|---|---|---|
fast |
Up to three search rounds. Stops when it has enough context. | Optimized for latency. Answers multi-hop queries. |
deep |
Plans its retrieval, and can read more records before it answers. | Runs more retrieval steps. Returns complete lists (up to 300 records) and counts. Takes longer. |
In Fast mode, each round can run several searches in parallel, for example a search of facts and a search of entities. The loop stops when it has enough context, or when a round finds no new evidence.
In Deep mode, Zep first plans the retrieval, and then runs the retrieval steps. It can list all the nodes or edges that match a filter, so it can return a complete list or a count. Deep mode runs more retrieval steps than Fast mode, so it takes longer.
In the video above, the graph comes from one company's email and calendar. For "Which weekly meetings covered workload and prioritization in February?", Fast mode found the meeting in about a second. Single-shot context retrieval didn't find it. For "How many meetings has Emilia Anglada attended?", Fast mode returned 20 of her meetings, and Deep mode found all 47 in about seven seconds. These times are from the runs in the video.
Smart Query and the Context Block #
Smart Query does not replace the Context Block. Smart Query and the Context Block retrieve different context.
The Context Block is single-shot. In one call, the Context Block retrieves the context for the current agent turn. The context can include facts that the agent did not know to ask for, for example a preference from two months ago. We wrote about this problem in Stop letting your agent decide what it needs to know.
Smart Query retrieves the context for a specific query. Smart Query explores the graph and plans each retrieval. Smart Query can thus retrieve multi-hop context, complete lists, and counts.
For more about the decisions behind a context architecture, see 3 decisions that shape every agent's context architecture.
Models, BYOM, and BYOC #
You cannot select the model, the tools, or the loop limits in the request. Zep runs the models of the managed service.
If your project uses its own LLM provider (BYOM), or if you run Zep in your own cloud (BYOC), Deep mode sends its model calls to your provider. Fast mode then needs a decision model in your LLM provider configuration. Without a decision model, set mode to deep.
Getting started with Smart Query #
Smart Query is now available to every Zep account and free for the next 90 days. Because it is experimental, the request, the response, the events, and the modes can change without a new API version. The operation is available through the Zep API and the Python, TypeScript, and Go SDKs. For the full reference, see the Zep guide Querying a Graph.
After the 90 days, Zep will charge for each use of Smart Query.
FAQ #
What is Smart Query in Zep? #
Smart Query is Zep's agentic retrieval API, the experimental graph.query operation. You send one natural-language query about one Zep graph. Zep explores the graph, plans each retrieval from what the previous retrievals returned, and returns the graph records that it retrieved. If you set generate_answer, Zep also returns an answer with citations to graph items.
How is Smart Query different from graph search? #
Graph search is single-shot. One call runs one search and returns one ranked list of a fixed size. Smart Query runs several retrieval steps for one query. It reads the results of each step and plans the next step, until it has enough context or reaches its limit. Smart Query can thus retrieve multi-hop context. In Deep mode, Smart Query also returns complete lists and counts.
What is the difference between Fast mode and Deep mode? #
Fast mode, the default, is optimized for latency, and it answers multi-hop queries. It runs at most three search rounds and stops when it has enough context. Deep mode runs more retrieval steps, and it returns complete lists and counts. It takes longer.
Does Smart Query replace the Context Block? #
Smart Query does not replace the Context Block. In one call, the Context Block retrieves the context for an agent turn, including facts that the agent did not know to ask for. Smart Query retrieves the context for a specific query that needs multi-hop retrieval, a complete list, or a count.
Can Smart Query search more than one graph? #
Smart Query cannot query more than one graph at this time. Each request accepts the UUID of exactly one graph, which can be a standard graph or a user graph. To query several graphs, send one request for each graph, and then combine the results in your application.
Does Smart Query cost money? #
Smart Query is free on all Zep accounts for the first 90 days. After that, Zep will charge for each use of Smart Query. Until then, you can test both modes on your own graphs. Because Smart Query is experimental, the request, the response, and the modes can change without a new API version.