> ## Documentation Index
> Fetch the complete documentation index at: https://docs.moorcheh.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Answer Generation

> Generate contextual AI-powered answers from your data

## Overview

Generate AI-powered answers to questions using your uploaded data as context. Moorcheh supports nine AI models for intelligent answer generation—the same catalog as the [Answer API](/api-reference/ai/generate).

<Info>
  The Answer API supports two modes: **Search Mode** (with namespace) and **Direct AI Mode** (empty namespace for direct model calls). Available models include Claude Sonnet 4.6, Claude Opus 4.6, Llama 4 Maverick, Amazon Nova Pro, DeepSeek, Qwen, and others—see the table below and the API reference for full details.
</Info>

## Supported AI Models

| Model ID                               | Name                 | Provider  | Description                                                                         |
| -------------------------------------- | -------------------- | --------- | ----------------------------------------------------------------------------------- |
| anthropic.claude-sonnet-4-6            | Claude Sonnet 4.6    | Anthropic | Fast flagship: coding, tools, long docs and RAG (\~1M context).                     |
| anthropic.claude-opus-4-6-v1           | Claude Opus 4.6      | Anthropic | Deepest reasoning and hardest tasks; pick when quality matters most (\~1M context). |
| meta.llama4-maverick-17b-instruct-v1:0 | Llama 4 Maverick 17B | Meta      | Long context, summarization, function calling, fine-tuning friendly.                |
| amazon.nova-pro-v1:0                   | Amazon Nova Pro      | Amazon    | Chat, math, and structured answers for AWS-style workloads.                         |
| deepseek.r1-v1:0                       | DeepSeek R1          | DeepSeek  | Step-by-step reasoning; math, logic, and technical explanations.                    |
| deepseek.v3.2                          | DeepSeek V3.2        | DeepSeek  | Efficient general Q\&A, multilingual, everyday RAG (\~164K context).                |
| openai.gpt-oss-120b-1:0                | OpenAI GPT OSS 120B  | OpenAI    | Large generalist: research-style answers and long-form writing.                     |
| qwen.qwen3-32b-v1:0                    | Qwen 3 32B           | Qwen      | Code and bilingual (EN/ZH) tasks in a smaller footprint.                            |
| qwen.qwen3-next-80b-a3b                | Qwen3 Next 80B A3B   | Qwen      | MoE model for long chats, docs, and code at scale (\~256K context).                 |

## Basic Usage

<CodeGroup>
  ```python Python SDK theme={null}
  from moorcheh_sdk import MoorchehClient

  client = MoorchehClient(api_key="your-api-key")

  # Generate answer from your data
  answer = client.get_answer(
      namespace="my-documents",
      query="What is Moorcheh?",
      ai_model="deepseek.r1-v1:0"
  )

  print(answer["answer"])
  ```

  ```bash cURL theme={null}
  curl -X POST "https://api.moorcheh.ai/v1/answer" \
    -H "Content-Type: application/json" \
    -H "x-api-key: your-api-key" \
    -d '{
      "namespace": "my-documents",
      "query": "What is Moorcheh?",
      "ai_model": "deepseek.r1-v1:0"
    }'
  ```
</CodeGroup>

## Search Mode vs Direct AI Mode

<Tabs>
  <Tab title="Search Mode">
    ### Search Mode (with namespace)

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

    ```python theme={null}
    # Answer based on your data
    answer = client.get_answer(
        namespace="my-documents",
        query="What are the main features?",
        ai_model="deepseek.r1-v1:0",
        top_k=5  # Number of documents to consider
    )
    ```

    **Best for:**

    * Q\&A over your documents
    * Knowledge base queries
    * Context-aware responses
  </Tab>

  <Tab title="Direct AI Mode">
    ### Direct AI Mode (empty namespace)

    Pass an empty string `""` as namespace to make direct calls to the AI model without searching your data.

    ```python theme={null}
    # Direct AI model call
    answer = client.get_answer(
        namespace="",  # Empty for direct mode
        query="Explain quantum computing",
        ai_model="deepseek.r1-v1:0"
    )
    ```

    **Best for:**

    * General knowledge questions
    * Code generation
    * Content creation
  </Tab>
</Tabs>

## Advanced Parameters

### Temperature Control

Control response creativity (0.0 - 2.0):

```python theme={null}
# More deterministic (lower temperature)
answer = client.get_answer(
    namespace="my-documents",
    query="List the API endpoints",
    ai_model="deepseek.r1-v1:0",
    temperature=0.1
)

# More creative (higher temperature)
answer = client.get_answer(
    namespace="my-documents",
    query="Write a blog post about our features",
    ai_model="deepseek.r1-v1:0",
    temperature=0.9
)
```

### Custom Prompts

Add custom instructions for the AI:

```python theme={null}
answer = client.get_answer(
    namespace="my-documents",
    query="Explain our pricing",
    ai_model="deepseek.r1-v1:0",
    header_prompt="You are a helpful sales assistant. Be concise and friendly.",
    footer_prompt="Always end with a call to action."
)
```

### Chat History

Maintain conversation context:

```python theme={null}
answer = client.get_answer(
    namespace="my-documents",
    query="What about the advanced features?",
    ai_model="deepseek.r1-v1:0",
    chat_history=[
        {"role": "user", "content": "What features do you offer?"},
        {"role": "assistant", "content": "We offer semantic search, vector storage..."}
    ]
)
```

## Response Format

Successful responses match the Answer API, including the `model` field (the model ID used for the reply):

```json theme={null}
{
  "answer": "Moorcheh is a lightning-fast semantic search engine...",
  "model": "deepseek.r1-v1:0",
  "context_count": 3,
  "query": "What is Moorcheh?"
}
```

## Model Selection Guide

<CardGroup cols={2}>
  <Card title="General Purpose" icon="star">
    **Claude Sonnet 4.6** — Fast flagship for coding, tools, long docs, and RAG
  </Card>

  <Card title="Advanced Reasoning" icon="brain">
    **Claude Opus 4.6** — Deepest reasoning when quality matters most
  </Card>

  <Card title="Long Context" icon="file">
    **Llama 4 Maverick** — Long context, summarization, and function calling
  </Card>

  <Card title="Code & Logic" icon="code">
    **DeepSeek R1** — Step-by-step reasoning, math, and technical explanations
  </Card>
</CardGroup>

## Best Practices

<AccordionGroup>
  <Accordion title="Choose the right model">
    * Use **Claude Sonnet 4.6** for general RAG, tools, and long documents
    * Use **DeepSeek R1** for math, logic, and step-by-step technical explanations
    * Use **Llama 4 Maverick** for very long context and summarization
  </Accordion>

  <Accordion title="Optimize top_k">
    * Use 3-5 documents for focused answers
    * Use 8-10 documents for comprehensive responses
    * Higher values may include irrelevant context
  </Accordion>

  <Accordion title="Set appropriate temperature">
    * 0.1-0.3 for factual, deterministic answers
    * 0.7 for balanced responses (default)
    * 0.9-1.0 for creative content generation
  </Accordion>

  <Accordion title="Use custom prompts wisely">
    * Add role context in `header_prompt`
    * Specify output format requirements
    * Keep prompts concise and clear
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Search API" icon="magnifying-glass" href="/guides/search">
    Learn about semantic search
  </Card>

  <Card title="Upload Data" icon="upload" href="/api-reference/data/upload-text">
    Add documents to your namespace
  </Card>

  <Card title="API Reference" icon="code" href="/api-reference/ai/generate">
    Complete AI generation API docs
  </Card>

  <Card title="Examples" icon="rocket" href="/guides/use-cases">
    See real-world examples
  </Card>
</CardGroup>
