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.
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.
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
Related Operations
- Search - Search for relevant context documents
- Upload Text Data - Add documents for AI context
- List Namespaces - View available namespaces for generation