Configure Knowledge Graph query parameters - Writer AI Studio

Documentation Index

Fetch the complete documentation index at: /llms.txt

Use this file to discover all available pages before exploring further.


This guide shows you how to customize Knowledge Graph query behavior using the query_config parameter. You can tune search algorithms, control response grounding, adjust content retrieval, and enable inline citations to configure Knowledge Graph responses for your specific use cases.

Overview

The query_config parameter allows you to fine-tune how Knowledge Graphs search, rank, and retrieve content. You can control the balance between keyword and semantic search, adjust how closely responses match source material, set relevance thresholds, and enable inline citations for source verification. You can use this parameter with:

Example

Here’s a chat completion example that demonstrates various query configuration parameters to configure Knowledge Graph responses:

cURL

curl --location --request POST 'https://api.writer.com/v1/chat' \
  --header "Authorization: Bearer $WRITER_API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "model": "palmyra-x5",
    "messages": [\
      {\
        "role": "user",\
        "content": "What are the key features of our product?"\
      }\
    ],
    "tools": [\
      {\
        "type": "graph",\
        "function": {\
          "description": "Search company knowledge base",\
          "graph_ids": ["<GRAPH_ID>"],\
          "subqueries": true,\
          "query_config": {\
            "grounding_level": 0.2,\
            "search_weight": 60,\
            "keyword_threshold": 0.6,\
            "semantic_threshold": 0.8,\
            "inline_citations": true\
          }\
        }\
      }\
    ]
  }'

Python

from writerai import Writer

# Initialize the Writer client
client = Writer()

# Configure Knowledge Graph tool with query parameters
tools = [{\
    "type": "graph",\
    "function": {\
        "description": "Search company knowledge base",\
        "graph_ids": ["<GRAPH_ID>"],\
        "subqueries": True,\
        "query_config": {\
            "grounding_level": 0.2,\
            "search_weight": 60,\
            "keyword_threshold": 0.6,\
            "semantic_threshold": 0.8,\
            "inline_citations": True\
        }\
    }\
}]

messages = [{"role": "user", "content": "What are the key features of our product?"}]

response = client.chat.chat(
    model="palmyra-x5",
    messages=messages,
    tools=tools,
    tool_choice="auto"
)

print(response.choices[0].message.content)

JavaScript

import { Writer } from 'writer-sdk';

// Initialize the Writer client
const client = new Writer();

// Configure Knowledge Graph tool with query parameters
const tools = [{\
    type: "graph",\
    function: {\
        description: "Search company knowledge base",\
        graph_ids: ["<GRAPH_ID>"],\
        subqueries: true,\
        query_config: {\
            grounding_level: 0.2,\
            search_weight: 60,\
            keyword_threshold: 0.6,\
            semantic_threshold: 0.8,\
            inline_citations: true\
        }\
    }\
}];

const messages = [{ role: "user", content: "What are the key features of our product?" }];

const response = await client.chat.chat({
    model: "palmyra-x5",
    messages: messages,
    tools: tools,
    tool_choice: "auto"
});

console.log(response.choices[0].message.content);

Find your Knowledge Graph ID using one of these methods:

Knowledge Graphs deployed to a specific team aren’t accessible via the API or SDK. To use a Knowledge Graph via the API or SDK, configure it with “All Teams” access in AI Studio.

Configure request parameters

Name Type Range Default Description
max_subquestions Integer 1-10 6 Maximum number of sub-questions to generate when processing complex queries. Set higher to improve detail, set lower to reduce response time. See Max sub-questions for details.
search_weight Integer 0-100 50 Controls the balance between keyword and semantic search in ranking results. See Search weight for details.
grounding_level Number 0.0-1.0 0.0 Controls how closely responses must match to source material. Set lower for grounded outputs, higher for creativity. See Grounding level for details.
max_snippets Integer 5-25 (recommended) 30 Maximum number of text snippets to retrieve from the Knowledge Graph for context. Works in concert with search_weight to control best matches vs broader coverage. Note: While technically supports 1-60, values below 5 may return no results due to RAG implementation. Recommended range is 5-25. See Max snippets for details.
max_tokens Integer 100-8000 4000 Maximum number of tokens the model can generate in the response. See Max tokens for details.
keyword_threshold Number 0.0-1.0 0.7 Threshold for keyword-based matching when searching Knowledge Graph content. Set higher for stricter relevance, lower for broader range. See Keyword threshold for details.
semantic_threshold Number 0.0-1.0 0.7 Threshold for semantic similarity matching when searching Knowledge Graph content. Set higher for stricter relevance, lower for broader range. See Semantic threshold for details.
inline_citations Boolean True/False False Whether to include inline citations within the response text. This is only available when making direct Knowledge Graph queries via the /v1/graphs/question endpoint. See Work with inline citations in Knowledge Graph responses for details.

Parameter details

Inline citations

When you enable inline_citations: true, the response includes source references directly in the text as [filename.pdf](cite_id) links. These citations correspond to entries in the references array, allowing you to verify information and trace claims back to their origins.Key features:

For detailed information about working with inline citations, see Work with inline citations in Knowledge Graph responses.

Max sub-questions

Maximum number of sub-questions to generate when processing complex queries. Higher values allow the system to break down complex questions into more detailed sub-queries.How it works:

When to adjust:

Search weight

Controls the balance between keyword and semantic search in ranking results.How it works:

When to adjust:

Grounding level

Controls how closely responses must be tied to source material. This is different from typical LLM temperature parameters. It specifically controls grounding to Knowledge Graph sources.How it works:

Examples:

When to adjust:

Max snippets

Maximum number of text snippets to retrieve from the Knowledge Graph for context. Works in concert with search_weight to control best matches vs broader coverage.How it works:

Important notes:

When to adjust:

Max tokens

Maximum number of tokens the model can generate in the response. This controls the length of the AI’s answer.How it works:

When to adjust:

Keyword threshold

Threshold for keyword-based matching when searching Knowledge Graph content.How it works:

When to adjust:

Semantic threshold

Threshold for semantic similarity matching when searching Knowledge Graph content.How it works:

Examples:

When to adjust:

Parameter interactions and performance

How parameters work together

Some parameters interact in ways that affect both results and performance:

Performance considerations

Recommended starting values

For most use cases, use the default values and adjust only if you need specific behavior. The defaults are designed to work well for general Knowledge Graph queries.

Usage examples

Chat completions with Knowledge Graph tool

Direct Knowledge Graph query

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": {
      "grounding_level": 0.2,
      "keyword_threshold": 0.6,
      "semantic_threshold": 0.8,
      "inline_citations": true
    }
  }'

Common configuration patterns

Research and analysis

Use this configuration for comprehensive research tasks where you need thorough analysis with source verification. Higher sub-questions and snippets provide more context, while inline citations help track sources.

{
  "max_subquestions": 8,
  "search_weight": 60,
  "grounding_level": 0.1,
  "max_snippets": 50,
  "max_tokens": 7000,
  "keyword_threshold": 0.6,
  "semantic_threshold": 0.7,
  "inline_citations": true
}

Quick answers

Use this configuration for fast, focused responses where speed and precision matter more than comprehensive analysis. Strict thresholds ensure high relevance with minimal processing time.

{
  "max_subquestions": 3,
  "search_weight": 80,
  "grounding_level": 0.0,
  "max_snippets": 15,
  "max_tokens": 2000,
  "keyword_threshold": 0.8,
  "semantic_threshold": 0.8,
  "inline_citations": false
}

Creative content generation

Use this configuration when you want the AI to interpret and build upon source material creatively. Lower thresholds allow more diverse content, while higher grounding level enables interpretive responses.

{
  "max_subquestions": 6,
  "search_weight": 40,
  "grounding_level": 0.6,
  "max_snippets": 30,
  "max_tokens": 5000,
  "keyword_threshold": 0.5,
  "semantic_threshold": 0.6,
  "inline_citations": false
}

Best practices

  1. Start with defaults: Begin with the default configuration and adjust based on your specific needs
  2. Test incrementally: Change one parameter at a time to understand its effect
  3. Consider your use case: Different applications, like research, Q&A, and content generation, benefit from different configurations
  4. Monitor performance: Track how different configurations affect response quality and processing time
  5. Balance precision and recall: Higher thresholds give more precise results but may miss relevant content

Next steps