Skip to main content
The chat endpoint takes a user question, retrieves relevant passages from your indexed documents, and generates a grounded answer with citations. It’s a turnkey RAG pipeline — no prompt engineering, no chunk assembly, no citation formatting.

The basics

response = client.chat("Summarize our refund policy in three bullet points")

print(response.answer)
for citation in response.citations:
    print(f"  → {citation.file_name} (p. {citation.page})")
Or via HTTP:
curl https://api.memic.ai/api/v1/chat \
  -H "X-API-Key: $MEMIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {"role": "user", "content": "Summarize our refund policy"}
    ]
  }'

Multi-turn conversations

Pass the full message history in each call. Memic is stateless — every request must include the complete conversation context:
messages = []

messages.append({"role": "user", "content": "What's our refund policy?"})
response = client.chat(messages=messages)
print(response.answer)
messages.append({"role": "assistant", "content": response.answer})

messages.append({"role": "user", "content": "What about digital products?"})
response = client.chat(messages=messages)
print(response.answer)

Citations

Every chat response includes structured citations pointing back to the source documents:
{
  "answer": "Customers may request a refund within 30 days of purchase...",
  "citations": [
    {
      "file_id": "...",
      "file_name": "refund-policy.pdf",
      "page": 4,
      "passage": "Customers may request..."
    }
  ]
}
Use these to render “read more” links in your UI or verify the LLM isn’t hallucinating.
  • Use search when you want passages to render as a list, or when you need raw retrieved content to feed into your own prompt
  • Use chat when you want an answer composed for you, with citations
Chat internally calls search and uses the results as context for an LLM. If you want full control over the LLM or prompt, use search + your own LLM call.

Recipe: Chatbot

A complete chatbot with memory walkthrough.

API reference

Full chat endpoint docs.