Integrating LLMs into corporate chatbots: the RAG approach and experiments

Michil Egorov, Gleb Panin, Daria Andreeva9 Aug 2024

Problem

The AI-Run team at X5 Tech builds chatbots for corporate portals that answer employee questions from internal documents. Sensitive data cannot go to external models, so they run open-source LLMs on their own servers. Such models have a short context, weak Russian and a tendency to hallucinate, and fine-tuning them is hard and expensive. A plain RAG pipeline (embed documents, find the nearest ones, let the LLM answer) almost never reaches the needed quality, because it ignores the structure of the data.

Example from the article: a user types only "vacation". The bot must work out whether this means requesting or rescheduling a vacation.

Solution in brief

Keep the LLM as is and improve retrieval in three steps: rewrite the user query with an LLM, search with vector search (multilingual-e5-large in Qdrant), then rerank the candidates with a cross-encoder. On the team's data, paraphrasing and reranking each lifted MAP@5, p@1 and p@5. Other query expansion methods (SelfQuery, FLARE) did not fit short queries with little metadata.

Questions this case answers
  • How to ground a self-hosted LLM in internal documents when data cannot leave the company and fine-tuning is too costly
  • How to improve retrieval quality for short, ambiguous user questions in a non-English document search pipeline
  • How to make an on-premise open-source LLM answer employee questions from internal documents without fine-tuning it?
  • How to improve the retrieval stage of a RAG chatbot when users send short, ambiguous queries?

Tools and methods

  • Query paraphrasing by LLM — turns short or typo-ridden queries into full questions
  • Vector search in Qdrant with multilingual-e5-large — first-stage retrieval
  • Vector search + SVM ensemble — best first stage on their data
  • Cross-encoder reranking — rescores each candidate against the query
  • Gradient boosting over scores — optional final ranker
  • LangChain — retriever variants and RAG chains
Continue reading — it's free

Google or a one-time email code. No password.