Ragfish Logo
Get In Touch
Ragfish Logo

Book a Demo

Chat

The Chat component is responsible for handling conversations in the Ragfish Framework.

It provides the interface for sending user messages, invoking the configured retrieval pipeline, and generating responses using the configured language model.

While an Assistant represents the overall AI application, Chat focuses on the conversational interaction between the user and the AI.

What is Chat?

At its simplest, a Ragfish chat flow looks like this:

User Message
     │
     ▼
    Chat
     │
     ▼
 Retriever
     │
     ▼
Relevant Context
     │
     ▼
    LLM
     │
     ▼
AI Response

The Chat component coordinates the interaction between the user, retriever, and language model.

Creating a Chat Instance

A Chat instance can be created by providing a retriever.

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

const chat = new Chat({
  retriever
});

The retriever provides the knowledge required to answer questions using your application's data.

Sending a Message

Once a Chat instance has been created, use message() to send a question.

const response = await chat.message(
  "What is Ragfish?"
);

console.log(response);

The message() operation sends the question through the configured Ragfish pipeline and returns the generated response.

Chat Request Flow

When a message is submitted, Ragfish processes the request through the retrieval and generation pipeline.

User
 │
 │  "What is Ragfish?"
 ▼
Chat
 │
 ▼
Retriever
 │
 ▼
Relevant Knowledge
 │
 ▼
Prompt / Context
 │
 ▼
Configured LLM
 │
 ▼
Response

The Chat component provides the conversational entry point while the underlying components handle retrieval and generation.

Chat and Retriever

The retriever is an important part of a RAG-based chat application.

For example:

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

const chat = new Chat({
  retriever
});

The retriever is responsible for finding relevant information from the configured knowledge store.

This allows the language model to generate responses using application-specific knowledge rather than relying only on its pretrained knowledge.

Chat and Settings

Chat works with the framework configuration defined through Settings.

For example:

import { Chat, Settings } from "@ragfish/core";
import {
  OpenAILLM,
  OpenAIEmbedding
} from "@ragfish/openai";

Settings.llm = new OpenAILLM({
  apiKey: process.env.OPENAI_API_KEY
});

Settings.embedModel = new OpenAIEmbedding({
  apiKey: process.env.OPENAI_API_KEY
});

const chat = new Chat({
  retriever
});

This keeps model configuration separate from the conversational logic.

Complete Example

The following example shows the basic relationship between Settings, the vector store, the retriever, and Chat.

import { Chat, Settings } from "@ragfish/core";
import {
  OpenAILLM,
  OpenAIEmbedding
} from "@ragfish/openai";
import {
  QdrantVectorStore,
  QdrantRetriever
} from "@ragfish/qdrant";

Settings.llm = new OpenAILLM({
  apiKey: process.env.OPENAI_API_KEY
});

Settings.embedModel = new OpenAIEmbedding({
  apiKey: process.env.OPENAI_API_KEY
});

const vectorStore = new QdrantVectorStore({
  url: process.env.QDRANT_URL,
  apiKey: process.env.QDRANT_API_KEY
});

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

const chat = new Chat({
  retriever
});

const response = await chat.message(
  "What is Ragfish?"
);

console.log(response);

Chat vs Assistant

Conceptually:

Application
    │
    ▼
Assistant
    │
    ▼
Chat
    │
    ▼
Retriever
    │
    ▼
Knowledge

An application can use the same chat capabilities across different assistants while each assistant provides its own context and configuration.

Retrieval-Powered Chat

The key difference between a basic LLM conversation and a Ragfish RAG conversation is the retrieval step.

A basic LLM request looks like:

User Question
     │
     ▼
    LLM
     │
     ▼
Response

A Ragfish retrieval-based conversation looks like:

User Question
     │
     ▼
   Chat
     │
     ▼
 Retriever
     │
     ▼
Relevant Knowledge
     │
     ▼
    LLM
     │
     ▼
Context-Aware Response

This enables applications to answer questions using their own knowledge sources.

Building on Chat

The Chat abstraction provides the foundation for more advanced conversational capabilities.

Depending on the framework implementation and future versions, applications can build capabilities such as:

  1. Streaming responses

  2. Conversation history

  3. Session management

  4. Multi-turn conversations

  5. Custom retrieval

  6. Multiple AI providers


These capabilities can be added without changing the fundamental Chat → Retriever → LLM architecture.

Best Practices

When working with Chat:

  1. Configure your AI provider before creating the chat instance.

  2. Configure the embedding model when retrieval requires embeddings.

  3. Use a focused retriever for each knowledge domain.

  4. Keep assistant-specific configuration separate from chat logic.

  5. Use environment variables for API credentials.

  6. Keep your knowledge sources organized and relevant to the assistant.

Next Steps

Now that you understand how Chat handles conversational requests, the next step is to learn how knowledge enters the Ragfish Framework