answer.generate
Generate AI-powered answers with RAG (retrieve from a text namespace) or direct LLM calls. Configure the LLM provider (Ollama, OpenAI, or Cohere) withmoorcheh configure before use.
POST /answer — see Generate AI Answer
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Generate AI answers using the Python client
moorcheh configure before use.
client.answer.generate(
*,
namespace: str,
query: str,
top_k: int | None = None,
threshold: float | None = None,
kiosk_mode: bool = False,
temperature: float | None = None,
ai_model: str | None = None,
header_prompt: str | None = None,
footer_prompt: str | None = None,
chat_history: list[dict[str, str]] | None = None,
structured_response: dict | None = None,
) -> dict[str, Any]
POST /answer — see Generate AI Answer
from moorcheh import MoorchehClient
with MoorchehClient("http://localhost:8080") as client:
response = client.answer.generate(
namespace="my-documents",
query="What are the main benefits?",
top_k=5,
)
print(response["answer"])
print(response["context_count"])
with MoorchehClient("http://localhost:8080") as client:
response = client.answer.generate(
namespace="",
query="Explain vector search in one paragraph",
temperature=0.5,
header_prompt="You are a concise technical writer.",
)
with MoorchehClient("http://localhost:8080") as client:
response = client.answer.generate(
namespace="",
query="Can you give an example?",
chat_history=[
{"role": "user", "content": "What is RAG?"},
{"role": "assistant", "content": "RAG combines retrieval with generation..."},
],
)
with MoorchehClient("http://localhost:8080") as client:
response = client.answer.generate(
namespace="docs",
query="Summarize the return policy",
structured_response={"enabled": True},
)
print(response.get("structured_data"))
| Field | Type | Required | Description |
|---|---|---|---|
query | string | Yes | User question |
namespace | string | Yes | Text namespace for RAG, or "" for direct LLM |
top_k | number | No | Chunks to retrieve (default 10) |
temperature | number | No | 0.0–2.0 (default 0.7) |
ai_model | string | No | Override configured LLM model |
chat_history | array | No | Prior turns |
header_prompt | string | No | System instruction |
footer_prompt | string | No | Trailing instruction |
kiosk_mode | boolean | No | Filter by threshold |
threshold | number | No | Required if kiosk_mode is true |
structured_response | object | No | { "enabled": true, "schema": {...} } |
| Field | Type | Description |
|---|---|---|
answer | string | Generated text |
model | string | Model ID used |
context_count | number | Chunks used for RAG |
query | string | Echo of input query |
structured_data | object | When structured output is enabled |
Was this page helpful?