Goal

Build a RAG pipeline that:
  1. Ingests documents into a memory store
  2. Retrieves relevant context for a query
  3. Augments the LLM prompt with retrieved context
  4. Returns a grounded answer with citations

Prerequisites

  • An Allternit API key
  • @allternit/sdk installed
  • Source documents (markdown, text, or PDF)

Implementation

1. Create a memory store

2. Ingest documents

3. Retrieve context

4. Augmented generation

5. Use it

Chunking helper

Explanation

  • Chunking — Documents are split into overlapping chunks to ensure relevant context isn’t split across boundaries.
  • Metadata — Each chunk stores its source file and position, enabling citations in the generated answer.
  • Low temperature — RAG prompts use low temperature (0.1) to reduce hallucination and stay grounded in the retrieved context.

Next steps

  • Add re-ranking — retrieve more chunks than needed, then re-rank with a cross-encoder.
  • Use prompt caching — cache the system prompt to reduce cost on repeated queries.
  • Add conversation history — include previous Q&A pairs in the context for multi-turn RAG.