Response with inline citations
Below is an example of a response from a Knowledge Graph that includes inline citations:
Corresponding references array
Below is the corresponding
references object that contains a direct snippet from the source file that was used to support the response:Enable inline citations
To enable inline citations in Knowledge Graph responses, setinline_citations: true in your query_config parameter when making direct Knowledge Graph queries via the /v1/graphs/question endpoint.
Citation format and correlation
Citation format
Inline citations appear in the answer from the LLM as[source_name](identifier), where:
source_nameis the display name of the source: either the filename for files, or the page title for web sourcesidentifieris the unique identifier used to correlate with the references array
- File sources: Uses the
citefield value, for example,[document.pdf](a1b2c3d4-e5f6-7890-abcd-ef1234567890) - Web sources: Uses the
urlfield value, for example,[Web Page Title](https://example.com/page)
Correlate citations with references
Inline citations correspond to entries in thereferences object. Correlation differs by source type:
- File sources: Citations use the
citefield from the file reference object as their identifier - Web sources: Citations use the
urlfield from the web reference object as their identifier
- Citation
[Acme-Product-Catalog.pdf](a1b2c3d4-e5f6-7890-abcd-ef1234567890)uses thecitefield from the file reference object - Citation
[Industry Trends Report](https://example.com/industry-trends)uses theurlfield from the web reference object
Link citations to source text with SDKs
When working with inline citations in SDK responses, you can programmatically link citation IDs to their corresponding source text. This enables you to build applications that display citations with their source material.Extract and correlate citations
These code samples demonstrate how to extract inline citations from Knowledge Graph responses and correlate them with their source material. The code parses citation markers in the answer text (like[filename](citation-id)) and matches them to the corresponding source text in the references object. Using similar patterns, you can extract citations and build applications that display citations with their source material.
Response format
Knowledge Graph responses include areferences object with files and web arrays. The files array contains file reference objects for file-based sources, and the web array contains web reference objects for web-based sources.
File sources
File sources appear in thereferences.files array.
| Field | Type | Description |
|---|---|---|
text | string | The actual text snippet from the source document that supports the response |
fileId | string | Unique identifier for the source file |
score | number | Internal score used during the retrieval process for ranking and selecting relevant snippets |
page | integer | Page number where the snippet was found in the source document |
cite | string | Unique identifier used in inline citations within the response text |
Web sources
Web sources appear in thereferences.web array.
| Field | Type | Description |
|---|---|---|
text | string | The exact text snippet from the web source that was used to support the response |
url | string | The URL of the web page where this content was found |
title | string | The title of the web page where this content was found |
score | number | Internal score used during the retrieval process for ranking and selecting relevant snippets |
Streaming responses
When using streaming responses with Knowledge Graph tools, thereferences object containing sources and citations appears in the last chunk of the stream. This means:
- Content chunks: The response text with inline citations is streamed progressively
- Final chunk: Contains the graph data with the complete
referencesobject - Citation processing: You need to collect all chunks and process the final one to access source text
Stream responses with SDKs
Next steps
- Learn about Knowledge Graph query configuration for tuning search parameters
- Explore Knowledge Graph tools for chat completions
- Check out direct Knowledge Graph queries for programmatic access