RAG (Retrieval-Augmented Generation) for AI Bot

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1212
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    852
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    815

RAG AI Bot Implementation (Retrieval-Augmented Generation)

RAG combines external knowledge retrieval with language models. Bot retrieves relevant documents/data, then generates answers based on that context. Better accuracy than pure LLM for domain-specific Q&A.

RAG Architecture

User Query → Vector Search → Retrieved Context → LLM → Answer

Implementation

import OpenAI from 'openai';
import { QdrantClient } from '@qdrant/js-client-rest';

const openai = new OpenAI();
const qdrant = new QdrantClient({ url: 'http://localhost:6333' });

async function ragQuery(userQuestion) {
  // 1. Embed question
  const questionEmbedding = await openai.embeddings.create({
    model: 'text-embedding-3-small',
    input: userQuestion,
  });

  // 2. Retrieve context
  const searchResults = await qdrant.search('knowledge-base', {
    vector: questionEmbedding.data[0].embedding,
    limit: 5,
    score_threshold: 0.7,
  });

  const context = searchResults.points
    .map(p => p.payload.text)
    .join('\n\n');

  // 3. Generate answer
  const response = await openai.chat.completions.create({
    model: 'gpt-4o-mini',
    messages: [
      {
        role: 'system',
        content: `Answer based on provided context. If answer not in context, say so.

Context:
${context}`,
      },
      { role: 'user', content: userQuestion },
    ],
    max_tokens: 500,
  });

  return {
    answer: response.choices[0].message.content,
    sources: searchResults.points.map(p => p.payload.source),
  };
}

Knowledge Base Setup

// Index documents
async function indexDocument(doc) {
  const chunks = chunkText(doc.content, { size: 500, overlap: 100 });

  const embeddings = await openai.embeddings.create({
    model: 'text-embedding-3-small',
    input: chunks,
  });

  const points = chunks.map((text, i) => ({
    id: generateId(),
    vector: embeddings.data[i].embedding,
    payload: {
      text,
      source: doc.source,
      docId: doc.id,
    },
  }));

  await qdrant.upsert('knowledge-base', { points });
}

Timeline

  • Setup Qdrant + embeddings — 1–2 days
  • Index knowledge base — 1 day
  • RAG implementation — 2 days
  • UI + streaming — 2–3 days
  • Quality assurance — 2–3 days