Docs/API Reference

RAG System

Beta

Retrieval-Augmented Generation — index your documents and get AI answers grounded in them.

RAG (Retrieval-Augmented Generation) lets the model answer from your own documents. You add documents once. When someone asks a question, Tarqa finds the most relevant passages and gives them to the model, so its answer is based on your data and not just general knowledge.

No code needed for the basics

In the dashboard, Build → Data Sources lets you upload files or add web pages, then switch on Data Sources under the Playground's message box. The API below does the same thing from your own app.

How it works

  1. 1
    Index your documents
    Your text is split into small chunks and turned into embeddings, a searchable form that captures meaning.
  2. 2
    Search by meaning
    A question is matched against those chunks by meaning (not just keywords), and each match gets a relevance score.
  3. 3
    Answer with context
    The best-matching chunks are given to the model along with the question, and it writes an answer grounded in them.

Use it from the API

  1. 1
    Create a conversation (your knowledge base)
    POST/api/v1/context/conversations/create
    Request
    {
      "title": "Product Documentation Q&A",
      "knowledgeBaseType": "custom"
    }
  2. 2
    Index a document
    POST/api/v1/rag/index
    Request
    {
      "conversationId": "conv_abc123",
      "documentText": "TarqaAI is a unified AI platform...",
      "metadata": {
        "source": "product-docs",
        "category": "features"
      }
    }
  3. 3
    Ask a question
    POST/api/v1/rag/chat
    Request
    {
      "conversationId": "conv_abc123",
      "message": "What AI models does TarqaAI support?",
      "model": "gemini-2.5-flash",
      "topK": 3
    }

    topK is how many matching chunks to give the model.

You can also search without generating an answer (POST /v1/rag/search) and check index size (GET /v1/rag/stats/:conversationId). See Endpoints.

FAQ

When should I use RAG instead of pasting text into the prompt?
When your content is large, changes over time, or is reused across many questions. RAG sends only the relevant parts, which keeps prompts small and answers focused.
How do I upload PDFs and other files?
See Document Q&A for file uploads and the full flow.
What does topK do?
It's how many matching chunks are passed to the model. Higher gives more context but uses more tokens.