Ragfish Logo
Get In Touch
Ragfish Logo

Book a Demo

Retrieval

Retrieval is the process of finding the most relevant knowledge for a user's question.

In a Retrieval-Augmented Generation (RAG) application, the language model does not need to rely only on its pretrained knowledge. Ragfish can first search your application's knowledge base, retrieve relevant content, and provide that content to the language model as context.

Retrieval is therefore the bridge between your stored knowledge and the AI response.

Where Retrieval Fits

Retrieval happens after knowledge has been ingested, chunked, embedded, and stored.

Knowledge Source
      │
      ▼
   Ingestion
      │
      ▼
   Chunking
      │
      ▼
  Embeddings
      │
      ▼
 Vector Store
      │
      │
      │
User Question
      │
      ▼
  Embedding
      │
      ▼
   Retriever
      │
      ▼
Relevant Chunks
      │
      ▼
      Chat
      │
      ▼
      LLM
      │
      ▼
   Response

The retrieval stage determines which pieces of stored knowledge are relevant to the user's question.

What Is a Retriever?

A retriever is responsible for searching a knowledge store and returning relevant information.

In Ragfish, a retriever works with a vector store.

For example:

import {
  QdrantVectorStore,
  QdrantRetriever
} from "@ragfish/qdrant";

const store = new QdrantVectorStore({
  // configuration
});

const retriever = new QdrantRetriever({
  vectorStore: store,
  collectionName: "knowledge"
});

The QdrantRetriever implementation connects the retrieval layer with the configured Qdrant vector store. The Ragfish master example uses the same pattern with a Qdrant collection named adm3.

Retrieval Request Flow

When a user submits a question, the retrieval process can be represented as:

User Question
      │
      ▼
Generate Query Embedding
      │
      ▼
Search Vector Store
      │
      ▼
Calculate Similarity
      │
      ▼
Rank Results
      │
      ▼
Return Relevant Chunk

The retrieved chunks are then provided to the chat layer for response generation.

Semantic Retrieval

Ragfish uses embeddings to support semantic retrieval.

Consider the following stored content:

Employees are entitled to 20 days of annual paid leave.

A user might ask:

How many vacation days can an employee take?

The wording is different, but the meaning is similar.

Semantic retrieval allows the system to identify the relevant content based on meaning rather than requiring an exact keyword match.

Vector Store and Retriever

The vector store and retriever have different responsibilities.

Component

Responsibility

Vector Store

Stores and searches vector representations

Retriever

Defines how relevant information is retrieved from the vector store

Conceptually:

Retriever
    │
    ▼
Vector Store
    │
    ▼
Search
    │
    ▼
Relevant Chunks

This separation allows the retrieval layer to remain independent from a specific vector database implementation.

Qdrant Retrieval

Ragfish provides a Qdrant integration through @ragfish/qdrant.

A basic setup looks like:

import {
  QdrantVectorStore,
  QdrantRetriever
} from "@ragfish/qdrant";

const store = new QdrantVectorStore({
  // Qdrant configuration
});

const retriever = new QdrantRetriever({
  vectorStore: store,
  collectionName: "knowledge"
});

This follows the retrieval pattern documented in the Ragfish framework example.

Retrieval with Chat

The retriever is passed to Chat.

import { Chat } from "@ragfish/core";

const chat = new Chat({
  retriever
});

A user can then ask a question:
const response = await chat.message(
  "How many methods can ADM3 store?"
);

console.log(response);

The documented Ragfish example follows this exact architecture:

QdrantVectorStore
        │
        ▼
QdrantRetriever
        │
        ▼
      Chat
        │
        ▼
    Response

Retrieval Context

The retriever returns relevant chunks rather than the entire knowledge base.

For example:

Knowledge Base
│
├── Document A
├── Document B
├── Document C
├── Document D
└── Document E

        │
        ▼

User Question

        │
        ▼

Retriever

        │
        ▼

Relevant Results
├── Document B - Chunk 4
├── Document D - Chunk 2
└── Document B - Chunk 5

Only the relevant context needs to be passed to the language model.

This helps keep the generated response focused on the user's question.

Retrieval Quality

Retrieval quality has a significant impact on the quality of the final AI response.

Even a powerful language model cannot reliably answer a knowledge-base question if the correct information is not retrieved.

Retrieval quality depends on several factors:

    1. Source quality

    2. Chunking strategy

    3. Embedding model

    4. Vector store configuration

    5. Query quality

    6. Retrieval strategy

    7. Metadata

This is why ingestion, chunking, embeddings, and retrieval should be designed as parts of the same pipeline.

Retrieval and Chunking

Chunking determines what the retriever can search.

Document
   │
   ▼
Chunking
   │
   ├── Chunk 1
   ├── Chunk 2
   ├── Chunk 3
   └── Chunk 4
          │
          ▼
      Embeddings
          │
          ▼
     Vector Store
          │
          ▼
       Retriever

If chunks are poorly structured, retrieval may return incomplete or irrelevant context.

For this reason, retrieval should always be evaluated together with the chunking strategy.

Retrieval and Metadata

Metadata can provide additional context for retrieval.

For example:

For example:
Chunk
├── Content
├── Document
├── Page
├── Section
└── Source

Metadata can be used to identify the origin of retrieved content and, depending on the retriever implementation, support filtering or other retrieval strategies.

Custom Retrievers

Ragfish's modular architecture allows retrieval to be separated from the underlying vector store.

This makes it possible to implement custom retrieval behavior for application-specific requirements.

Potential retrieval strategies include:

    1. Semantic retrieval

    2. Metadata-based retrieval

    3. Filtered retrieval

    4. Hybrid retrieval

    5. Domain-specific retrieval

The exact interfaces and extension points should follow the retriever APIs exposed by the installed Ragfish version.

Retrieval in the Complete Pipeline

Retrieval is one stage in the complete Ragfish request lifecycle.

KNOWLEDGE PIPELINE

Knowledge
    │
    ▼
Ingestion
    │
    ▼
Chunking
    │
    ▼
Embeddings
    │
    ▼
Vector Store
    │
    │
    └────────────────────┐
                         │
                    RETRIEVAL
                         ▲
                         │
User Question ───────────┘
                         │
                         ▼
                       Chat
                         │
                         ▼
                        LLM
                         │
                         ▼
                     Response

This architecture separates knowledge preparation from knowledge retrieval while keeping the complete workflow connected.

Best Practices

When designing retrieval systems:

    1. Use high-quality source content.

    2. Choose a chunking strategy appropriate for the source.

    3. Use an embedding model suitable for your content and language.

    4. Keep related knowledge organized into appropriate collections or knowledge spaces.

    5. Preserve useful metadata.

    6. Test retrieval using real user questions.

    7. Evaluate retrieved context before tuning the language model.

    8. Keep retrieval logic independent from application-specific business logic.

What's Next?

Retrieval provides the knowledge required to answer a user's question. The next part of the framework is understanding the contracts that allow these components to work together.

Continue to Interfaces to learn about the common TypeScript interfaces used to keep Ragfish components modular, interchangeable, and extensible.