Ragfish Logo
Get In Touch
Ragfish Logo

Book a Demo

Examples

This page provides complete examples of using OpenAI with the Ragfish Framework.

The examples demonstrate how to combine the OpenAI language model and embedding model with Ragfish Core, Qdrant, retrieval, and chat.

Basic OpenAI Configuration

The simplest OpenAI configuration uses OpenAILLM for response generation and OpenAIEmbedding for embeddings.

import { 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
});

This configuration makes the OpenAI models available to the Ragfish Framework.

OpenAI with Qdrant

A complete RAG application can combine OpenAI with Qdrant.

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

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

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

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

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

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

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

const chat = new Chat({
 retriever
});

The architecture is:

OpenAI Embedding
      |
      v
 Vector Store
      |
      v
   Retriever
      |
      v
     Chat
      |
      v
 OpenAI LLM
      |
      v
   Response

Ask a Question

Once the Chat instance is configured, you can send a question.

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

console.log(response);

The question is processed through the retrieval and generation pipeline.

User Question
     |
     v
OpenAI Embedding
     |
     v
Vector Search
     |
     v
Relevant Knowledge
     |
     v
OpenAI LLM
     |
     v
AI Response

Complete Example

The following example combines the core Ragfish components into a single application.

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

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

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

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

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

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

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

const chat = new Chat({
 retriever
});

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

console.log(response);

The current Ragfish master example follows this same architecture, using OpenAIEmbedding, OpenAILLM, QdrantVectorStore, QdrantRetriever, and Chat together.

Example: Knowledge-Based Question

The strength of this architecture is that the response can be based on your own knowledge base.

For example, suppose your vector store contains documentation about a product.

A user asks:

How many methods can ADM3 store?

The request follows this flow:

User Question
     |
     v
OpenAI Embedding
     |
     v
Qdrant Search
     |
     v
Relevant ADM3 Content
     |
     v
OpenAI LLM
     |
     v
Answer

This example is based on the ADM3 retrieval example already documented in the Ragfish master architecture.

Using a Different Knowledge Collection

The collection used by the retriever determines which knowledge space is searched.

For example:
const retriever = new QdrantRetriever({
 vectorStore: store,
 collectionName: "product-documents"
});

Another assistant could use a different collection:

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

This allows different assistants or application features to work with different knowledge domains.

Multiple AI Assistants

The same OpenAI integration can be used by multiple assistants.

Ragfish Application
      |
      +-- HR Assistant
      |      |
      |      +-- HR Knowledge
      |
      +-- Support Assistant
      |      |
      |      +-- Product Knowledge
      |
      +-- Compliance Assistant
             |
             +-- Compliance Knowledge

Each assistant can use its own knowledge and retrieval configuration while sharing the same OpenAI provider integration.

The master architecture describes this assistant-oriented approach as part of Ragfish's broader framework direction.

Error Handling

External AI and vector database services can fail, so production applications should handle errors.

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

 console.log(response);
} catch (error) {
 console.error("Chat request failed:", error);
}

For production applications, log technical details internally and return an appropriate user-facing message.

Environment Configuration

Keep provider credentials outside the source code.