This guide shows you how to work with inline citations in Knowledge Graph responses. Inline citations show which specific sources support each part of the response, enabling you to verify information and trace claims back to their origins.

Response with inline citations

Below is an example of a response from a Knowledge Graph that includes inline citations:
Acme Corp's flagship product line includes three
main categories: industrial tools, consumer
electronics, and automotive parts. The industrial
tools division offers precision manufacturing
equipment with advanced automation capabilities
[Acme-Product-Catalog.pdf](a1b2c3d4-e5f6-7890-abcd-ef1234567890).

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:
{"files": [
  {
    "text": "Industrial Tools Division: Our precision manufacturing equipment features advanced automation capabilities with real-time monitoring systems that reduce operational downtime by up to 40% through predictive maintenance algorithms.",
    "fileId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "score": 0.95,
    "page": 12,
    "cite": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
  }
]}

Enable inline citations

To enable inline citations in Knowledge Graph responses, set inline_citations: true in your query_config parameter when making direct Knowledge Graph queries via the /v1/graphs/question endpoint.
cURL
curl --location --request POST 'https://api.writer.com/v1/graphs/question' \
  --header "Authorization: Bearer $WRITER_API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "graph_ids": ["<GRAPH_ID>"],
    "question": "What are the key features of our product?",
    "query_config": {
      "inline_citations": true
    }
  }'

Citation format and correlation

Citation format

Inline citations appear in the answer from the LLM as [filename.pdf](cite_id), where:
  • filename.pdf is the name of the source file
  • cite_id is a unique identifier that matches the cite field in the references object

Correlate citations with references

Inline citations in the response text correspond to entries in the references array. Each citation uses the cite field from the references array as its identifier. Example correlation: Here’s an example showing how inline citations correlate with the references array: Response text:
Acme Corp's flagship product line includes three main categories: industrial tools, consumer electronics, and automotive parts.
The industrial tools division offers precision manufacturing equipment with advanced automation capabilities
[Acme-Product-Catalog.pdf](a1b2c3d4-e5f6-7890-abcd-ef1234567890). These tools feature real-time monitoring and
predictive maintenance systems that reduce downtime by up to 40% [Acme-Product-Catalog.pdf](a1b2c3d4-e5f6-7890-abcd-ef1234567890).
References object:
{"files": [
  {
    "text": "Industrial Tools Division: Our precision manufacturing equipment features advanced automation capabilities with real-time monitoring systems that reduce operational downtime by up to 40% through predictive maintenance algorithms.",
    "fileId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "score": 0.95,
    "page": 12,
    "cite": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
  },
  {
    "text": "Consumer Electronics: Smart thermostat series with AI-powered learning algorithms that automatically adapt to user behavior patterns, optimizing energy consumption and comfort levels.",
    "fileId": "b2c3d4e5-f6g7-8901-bcde-f23456789012",
    "score": 0.88,
    "page": 25,
    "cite": "b2c3d4e5-f6g7-8901-bcde-f23456789012"
  }
]}
Citation mapping:
  • Citation [Acme-Product-Catalog.pdf](a1b2c3d4-e5f6-7890-abcd-ef1234567890) uses the cite field from the first reference object
  • Citation [Acme-Product-Catalog.pdf](b2c3d4e5-f6g7-8901-bcde-f23456789012) uses the cite field from the second reference object

Response format

Knowledge Graph responses include a references object with files and web objects. The files object contains file objects for file-based sources and the web object contains web objects for web-based sources.

File sources (references.file objects)

FieldTypeDescription
textstringThe actual text snippet from the source document that supports the response
fileIdstringUnique identifier for the source file
scorenumberInternal score used during the retrieval process for ranking and selecting relevant snippets
pageintegerPage number where the snippet was found in the source document
citestringUnique identifier used in inline citations within the response text

Web sources (references.web objects)

FieldTypeDescription
textstringThe actual text snippet from the web page that supports the response
urlstringURL of the source web page
titlestringTitle of the web page
scorenumberInternal score used during the retrieval process for ranking and selecting relevant snippets
citestringUnique identifier used in inline citations within the response text

Streaming responses

When using streaming responses with Knowledge Graph tools, the references object containing sources and citations is sent 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 references object
  • Citation processing: You need to collect all chunks and process the final one to access source text

Next steps