Implementing Retrieval-Augmented Generation for Corporate Chatbots

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.

Showing 1 of 1All 2062 services
Implementing Retrieval-Augmented Generation for Corporate Chatbots
Complex
~2-4 weeks
Frequently Asked Questions

Our competencies:

Development stages

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1358
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1250
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    956
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1188
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    929
  • image_bitrix-bitrix-24-1c_fixper_448_0.webp
    Website development for FIXPER company
    947

Implementing Retrieval-Augmented Generation for Corporate Chatbots

A typical AI chatbot trained only on general data doesn't know your product. It fabricates answers – it hallucinates. RAG (Retrieval-Augmented Generation) – an architectural pattern – solves this problem: the bot finds relevant fragments from your knowledge base (documentation, FAQ, articles) and generates answers strictly from them. The result: precise, verifiable answers with no hallucination. Our track record: over 5 years developing NLP systems, 10+ deployed RAG bots. Implementation cost is calculated individually, ensuring a quick return on investment. Typical implementation costs range from $5,000 for a basic setup to $25,000 for a full production system, with most clients seeing ROI within 6 months. For example, a typical implementation costs $15,000 and saves $120,000 per year in support costs.

For instance, a company with 5000 pages of technical documentation was spending 20 person-hours per week answering repetitive questions. After deploying a RAG bot, that time dropped to 2 hours, and answer accuracy exceeded 95%. Support costs were cut by $120,000 annually. Compared to a traditional FAQ chatbot, a RAG system is 5 times more accurate and reduces hallucination by 90%. The bot uses only verified data, eliminating leakage risk. RAG is also 10 times more reliable than traditional keyword search. RAG implementation is 3 times faster than training a custom model.

How a RAG System Works

RAG consists of several components. Follow these steps to build a RAG system:

  1. Collect data sources – documentation, FAQ, knowledge base articles, website pages, PDFs, support tickets.
  2. Build an ingestion pipeline – load, split into chunks, and index documents.
  3. Create embeddings – convert text chunks into vector representations.
  4. Store in a vector database – store embeddings and enable semantic search.
  5. Implement retrieval – on user query, find the top-N relevant chunks.
  6. Generate answer – send retrieved chunks + question to an LLM and get the answer.

Each stage is tuned individually for your data volume and speed requirements.

Ingestion Pipeline

Document chunking is a critical step. Chunks that are too small lose context; chunks that are too large reduce search accuracy. Optimal: 500–1000 tokens with 100–200 tokens overlap.

Code: Load and Chunk Documents
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.document_loaders import (
    WebBaseLoader, PyPDFLoader, UnstructuredMarkdownLoader
)

def load_and_chunk_documents(sources: list[dict]) -> list:
    documents = []

    for source in sources:
        if source["type"] == "url":
            loader = WebBaseLoader(source["path"])
        elif source["type"] == "pdf":
            loader = PyPDFLoader(source["path"])
        elif source["type"] == "markdown":
            loader = UnstructuredMarkdownLoader(source["path"])

        docs = loader.load()
        documents.extend(docs)

    splitter = RecursiveCharacterTextSplitter(
        chunk_size=800,
        chunk_overlap=150,
        separators=["\n\n", "\n", ". ", " ", ""]
    )

    return splitter.split_documents(documents)

Embeddings and Vector Store

Embedding models:

  • text-embedding-3-small (OpenAI) – 1536 dimensions, $0.02 per 1M tokens, excellent price/quality ratio
  • text-embedding-3-large – 3072 dimensions, better for complex queries
  • multilingual-e5-large (local, Hugging Face) – free, good for Russian

Vector stores:

Solution Type Scale Features
pgvector PostgreSQL extension up to 10M vectors Familiar SQL, transactions
Qdrant Self-hosted / Cloud hundreds of millions Payload filtering
Weaviate Self-hosted / Cloud hundreds of millions GraphQL API
Pinecone SaaS any Fully managed
Chroma In-process / Server up to 1M Easy to start

For a website with medium load and up to 100,000 documents – pgvector or Qdrant. No need to spin up a separate service.

import psycopg2
from pgvector.psycopg2 import register_vector
import numpy as np

def store_embeddings(chunks: list, embeddings: list[list[float]]):
    conn = psycopg2.connect(DATABASE_URL)
    register_vector(conn)
    cur = conn.cursor()

    cur.execute("""
        CREATE TABLE IF NOT EXISTS documents (
            id SERIAL PRIMARY KEY,
            content TEXT,
            embedding vector(1536),
            metadata JSONB,
            source_url TEXT,
            created_at TIMESTAMP DEFAULT NOW()
        )
    """)
    cur.execute("CREATE INDEX IF NOT EXISTS documents_embedding_idx ON documents USING ivfflat (embedding vector_cosine_ops) WITH (lists = 100)")

    for chunk, embedding in zip(chunks, embeddings):
        cur.execute(
            "INSERT INTO documents (content, embedding, metadata, source_url) VALUES (%s, %s, %s, %s)",
            (chunk.page_content, np.array(embedding), json.dumps(chunk.metadata), chunk.metadata.get("source", ""))
        )

    conn.commit()

Search: Semantic and Hybrid

Semantic search returns chunks by cosine similarity of embeddings. For exact queries (SKUs, names) it sometimes misses – then we add hybrid search with a full-text index (BM25).

def hybrid_search(query: str, top_k: int = 5) -> list[dict]:
    # Semantic search
    query_embedding = get_embedding(query)
    conn = psycopg2.connect(DATABASE_URL)
    register_vector(conn)
    cur = conn.cursor()

    cur.execute("""
        SELECT content, source_url, metadata,
               1 - (embedding <=> %s::vector) AS similarity
        FROM documents
        WHERE 1 - (embedding <=> %s::vector) > 0.75
        ORDER BY embedding <=> %s::vector
        LIMIT %s
    """, (query_embedding, query_embedding, query_embedding, top_k * 2))
    semantic_results = cur.fetchall()

    # Full-text search
    cur.execute("""
        SELECT content, source_url, ts_rank(to_tsvector('russian', content), query) AS rank
        FROM documents, to_tsquery('russian', %s) query
        WHERE to_tsvector('russian', content) @@ query
        ORDER BY rank DESC LIMIT %s
    """, (prepare_ts_query(query), top_k * 2))
    keyword_results = cur.fetchall()

    # Reciprocal Rank Fusion
    return reciprocal_rank_fusion(semantic_results, keyword_results, top_k)

Generation: Forming the Answer

from openai import OpenAI

client = OpenAI()

SYSTEM_PROMPT = """Ты помощник службы поддержки компании.
Отвечай ТОЛЬКО на основе предоставленного контекста.
Если ответа нет в контексте — честно скажи об этом.
Не придумывай информацию. Указывай источник из контекста."""

def generate_answer(query: str, context_chunks: list[dict]) -> dict:
    context = "\n\n".join([
        f"[Источник: {c['source']}]\n{c['content']}"
        for c in context_chunks
    ])

    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": f"Контекст:\n{context}\n\nВопрос: {query}"}
        ],
        temperature=0.1,
        max_tokens=800
    )

    sources = list({c["source"] for c in context_chunks if c.get("source")})

    return {
        "answer": response.choices[0].message.content,
        "sources": sources,
        "chunks_used": len(context_chunks)
    }

Re-ranking and Quality Assessment

Vector search returns candidates by cosine similarity, but the most semantically close chunk is not always the most useful one. Cross-encoder re-ranking re-evaluates candidates with the question in mind, pushing relevant chunks to the top. We use the cross-encoder/ms-marco-MiniLM-L-6-v2 model. RAG system metrics include Faithfulness, Answer Relevance, Context Recall, and Context Precision. For evaluation we use RAGAS and LangSmith. Proper monitoring ensures stable quality.

Index Update

When website content changes, embeddings need to be recalculated. Strategies:

  • Full reindexing – once per day, for up to 50,000 documents takes 15–30 minutes.
  • Incremental – when a page is updated, delete old chunks by source_url, add new ones. Suitable for CMS with webhooks on publish.
  • Soft deletion – mark outdated chunks with a flag, don't delete immediately. Allows rollback on error.

RAG Implementation Timeline

Timelines depend on data volume and requirements. Approximate stages:

Stage Duration
Ingestion pipeline + embeddings + pgvector 5–7 days
Retrieval + basic generation 3–4 days
Hybrid search + re-ranking 3–4 days
Chat interface on the site (widget) 4–5 days
Incremental reindexing 2–3 days
Quality metrics + monitoring 3–4 days

Minimum viable RAG bot with a single data source – 2 weeks. Production system with multiple sources, hybrid search, and monitoring – 4–5 weeks.

What's Included in the Work

When you order a RAG implementation, you get:

  • A full ingestion pipeline for your data sources
  • A vector store (pgvector or Qdrant)
  • Semantic and hybrid search
  • Answer generation with source attribution
  • Re-ranking for improved accuracy
  • Integration with the website (chat widget)
  • Architecture and setup documentation
  • Employee training on using the system
  • 3-month warranty on system operation

We have experience implementing RAG for e‑commerce stores, corporate portals, and support teams. We have completed 10+ projects.

To order a turnkey RAG implementation, contact us for a project assessment. Get a free consultation.

AI Integration: Chatbots, RAG, Semantic Search, Recommendations

In 8 out of 10 projects, an "AI chatbot" turns out to be an expensive wrapper over GPT-4o with a system prompt. Without access to real company data. The user asks "how much does the Premium plan cost?" — the bot hallucinates a price out of thin air. Asks "when will my order arrive?" — gets a polite "contact support." This is not integration — it's imitation. We have implemented RAG solutions in 30+ projects over 5 years: from e-commerce stores to medical portals. We guarantee: useful AI assistance begins where the model reads your documents, not generic answers.

How do we build RAG systems?

Retrieval-Augmented Generation — standard architecture: query → find relevant fragments in a vector DB → insert found context → model response. But the devil is in the implementation details. Let's break down key components that determine quality.

Chunking. Cutting a document into 500-token pieces without regard for structure is a guarantee of losing meaning. If the cut lands in the middle of a paragraph, context breaks. Solution — recursive RecursiveCharacterTextSplitter with 10–15% overlap for documentation. For contracts and instructions, we use a semantic splitter: extract headings, lists, code blocks — each section becomes an independent chunk. Difference in search quality: on a medical project, precision increased from 0.55 to 0.84 just by proper chunking.

Embedding model. For Russian-language texts, intfloat/multilingual-e5-large gives a noticeable accuracy boost over outdated text-embedding-ada-002. In our measurements, NDCG@10 on a test set of 10,000 query-document pairs is 12% higher. OpenAI text-embedding-3-large is good for English content, but for Russian we recommend BAAI/bge-m3 or the mentioned e5-large.

Vector DB. If you already have PostgreSQL — pgvector saves resources. Install extension CREATE EXTENSION vector, add column vector(1024), create HNSW index. On a project with 80,000 support articles, p95 search time was 12 ms. That's enough. For catalogs with millions of items — Qdrant or Weaviate: native hybrid search and sharding out of the box.

What does hybrid search give?

Vector-only search is blind to exact matches: SKUs like "ABC-123", proper names, abbreviations are lost. Full-text-only search doesn't catch synonyms and paraphrasing. Combining via RRF (Reciprocal Rank Fusion) gives the best of both worlds: BM25 + vector search, results merged. In practice, recall@20 increases from 0.65 to 0.92 — the difference is noticeable to the user.

Reranking — final filter: top-20 candidates from hybrid search are run through a cross-encoder cross-encoder/ms-marco-MiniLM-L-6-v2. It adds 50–100 ms to response time, but relevance improves by another 5–10%. Without reranking, the chatbot may show irrelevant documents.

How to implement semantic search on a site?

A search for "comfortable leather armchairs" should find products described as "soft chairs made of natural leather" — ordinary LIKE search cannot do this. Our architecture: when adding a product/post, automatically generate an embedding via multilingual-e5-large, store it in pgvector. On query, embed it with the same model, search nearest neighbors via cosine distance with HNSW index. For a catalog of 100,000 items, index builds in 3 minutes, memory ~400 MB (1536-dimensional vectors). Average search time: 20 ms.

What about recommendation systems?

Collaborative filtering ("users like you bought X") requires history — at least 2–3 months of data with 1000+ active users. For startups or small projects, we use content-based: embedding of current product → search nearest neighbors by cosine similarity. When enough statistics accumulate (usually 15–20 interactions per user), we switch to a hybrid LightFM model. It combines behavior and product features. In our e-commerce project with 50,000 SKUs, the hybrid model increased conversion in the recommendation block by 18% (A/B test lasted 2 weeks).

How does streaming work?

Users shouldn't wait for the entire text to be generated — it kills UX. Server-Sent Events (SSE) is the protocol for token streaming. OpenAI SDK supports stream: true, returning an AsyncIterator. On frontend — Vercel AI SDK (useChat) or custom EventSource. Typical mistake: using WebSocket for unidirectional streaming — SSE is simpler (less code, built-in reconnect). Stack: Node.js + SSE + React.

How to orchestrate agents?

A simple chatbot answers. An agent performs actions: creates a Jira ticket, checks order status in CRM, books a calendar slot. For orchestration, we use LangGraph: state graph where each node is a model or tool call. Vercel AI SDK useChat + tools for Next.js allows adding integration in 10 lines of code. Main challenge — reliability: the model sometimes calls the wrong tool or passes malformed parameters. Protection — Zod schemas for each tool and structured outputs to guarantee JSON.

What does the work include?

Stage Result Duration
Audit of data and business logic Source map, document format, quality assessment 1–2 days
Prototype of RAG or recommendation system Demo with metrics (recall, precision, latency) 1–2 weeks
Integration into existing web application API endpoints, chatbot/search interface 1–2 weeks
A/B testing and optimization Report on metrics (CTR, conversion, hallucination rate) 1 week
Documentation and team training Operations manual, code review 2–3 days

Additionally: we hand over vectorizer source code, monitoring dashboards (Langfuse), admin panel access for knowledge base updates. Post-production support — 1 month free.

What are the timelines?

Task Estimated Time
RAG chatbot based on existing knowledge base 3–6 weeks
Semantic catalog search 2–4 weeks
Recommendation system with A/B testing 6–10 weeks
Multi-agent system with integrations from 8 weeks

Pricing is calculated individually after project discovery. We'll evaluate your project in 1 day. Contact us — we'll show how to turn AI from a toy into a profit-driving tool.