_meiliSearchProgress (which reports what searches are being performed) and _meiliSearchSources (which returns the actual documents used).
Include source tools in your request
To receive source documents, include both_meiliSearchProgress and _meiliSearchSources in the tools array of your chat completions request:
_meiliSearchProgress reports which searches are being performed and assigns a call_id to each search. _meiliSearchSources then returns the documents found, referencing the same call_id so you can associate sources with their corresponding queries.
Understand the response structure
During a streamed response, tool calls arrive as chunks alongside content chunks. Here is the sequence of events:1. Search progress
When the agent decides to search an index, you receive a_meiliSearchProgress tool call:
movies index for “best sci-fi movies”. The call_id value (abc123) links this search to its results.
2. Source documents
After the search completes, you receive a_meiliSearchSources tool call with the matching documents:
call_id matches the progress event, so you know these documents came from the “best sci-fi movies” search on the movies index.
3. Generated answer
Content chunks contain the AI-generated answer, which is based on the retrieved documents.Extract sources in JavaScript
Parse tool calls from the stream and collect sources into a structured object:sources contains all search queries and their corresponding documents, keyed by call_id.
Display sources in your UI
Here is a simple pattern for displaying sources alongside the chat response. This example uses plain HTML, but the same approach works with any frontend framework:Common UI patterns
There are several ways to present source documents to users:- Inline citations: Number each source and reference them in the response text (e.g., [1], [2])
- Collapsible panel: Show a “Sources” section below the response that users can expand
- Side panel: Display sources in a sidebar next to the conversation
- Footnotes: List sources at the bottom of each response
Handle multiple searches
A single user question may trigger multiple searches across different indexes. For example, asking “Compare the pricing and features of Product X” might search both aproducts index and a pricing index.
Each search produces its own call_id, so you can group and display sources per search:
Next steps
- Learn about all available tools in the chat tooling reference
- Configure guardrails to improve response accuracy
- Stream chat responses for real-time delivery