Skip to main content

answer.generate

Submits a query to a text namespace to get a conversational answer generated by an LLM.

Parameters

str
required
The single text namespace to search for context, or empty string "" for Direct AI Mode.
str
required
The user’s question or prompt.
int
default:"10"
Number of top relevant chunks for your query across given namespace. Default is 10.
Optional[float]
Minimum relevance score threshold (0-1) to filter out chunks below this relevance level. Required when kiosk_mode is true. Only used in Search Mode.
bool
default:"False"
Enable kiosk mode to filter chunks below certain relevance. When kiosk mode is on, threshold is required. Only used in Search Mode.
str
default:"deepseek.r1-v1:0"
The identifier for the LLM to use. See Available Models.
Optional[List[Dict]]
A list of previous conversation turns to maintain context.
float
default:"0.7"
The sampling temperature for the LLM (0-1). Defaults to 0.7.
Optional[str]
Custom instruction for AI behavior.
Custom instruction to append.
Returns: Dict[str, Any] - A dictionary containing the answer, model, and other metadata. Raises: NamespaceNotFound, InvalidInputError.

Search Mode Example (with namespace)

Generate Answer Example

Direct AI Mode Example (empty namespace)

Direct AI Mode Example

Conversational AI with History

Conversational AI with History

Complete Example

Complete Search and AI Workflow

AI Response Structure

AI generation responses contain:
AI Response Format

API Modes

Search Mode (with namespace)

When you provide a namespace, the API searches your data for relevant context and uses it to generate contextual answers.

Direct AI Mode (empty namespace)

When you pass an empty string "" as namespace, the API makes a direct call to the AI model without searching your data.
Field Restrictions (use snake_case in JSON; matches the REST API):
  • Empty Namespace Mode: Only these fields are allowed: namespace, query, temperature, chat_history, footer_prompt, header_prompt, ai_model, and structured_response when applicable
  • Provided Namespace Mode: All fields are allowed: namespace, query, top_k, threshold, type, kiosk_mode, ai_model, chat_history, header_prompt, footer_prompt, temperature, and structured_response when applicable

Available Models

Temperature Guide

  • 0.0-0.5: Conservative, factual responses - best for technical documentation
  • 0.5-1.0: Balanced creativity - good for general Q&A
  • 1.0-2.0: More creative and varied responses - use carefully for factual content

Relevance Score Threshold

Results are scored using Information Theoretic Similarity (ITS), providing nuanced relevance measurements:

Best Practices

  • Provide clear, specific questions
  • Use chat history for conversational experiences
  • Adjust temperature based on creativity needs
  • Choose appropriate AI models for your use case
  • For Search Mode: Higher top_k values provide more context but may increase response time
  • For Search Mode: The threshold parameter can be used to filter low-relevance results

Use Cases

  • Customer Support: Answer customer questions using your documentation
  • Internal Q&A: Help employees find answers in company knowledge bases
  • Educational Tools: Create AI tutors using educational content
  • Research Assistance: Get insights from research papers and publications
  • Technical Support: Provide technical answers based on documentation
  • Content Creation: Generate content based on existing materials