π€ Building a Custom AI Chatbot with RAG and Qdrant using C#
π― Purpose of the Sample
The Custom Chatbot with RAG and Qdrant Demo illustrates how to integrate LM-Kit.NET with a Qdrant vector store to build a chatbot that uses Retrieval-Augmented Generation (RAG). This solution demonstrates how semantic search and large language models (LLMs) can be combined in a .NET application to provide accurate, context-aware responses from stored vector embeddings.
π₯ Industry Target Audience
This sample benefits developers and organizations in areas like:
- ποΈ Customer Support: Query large knowledge bases with fast, relevant results.
- π Education: Build tutoring systems based on textbooks and training content.
- π₯ Healthcare: Provide real-time answers from medical guidelines or literature.
- π¦ Logistics & Industry: Search across technical documentation and manuals.
- ποΈ E-commerce: Enable chat-based access to product catalogs and FAQs.
π Problem Solved
Managing large corpora of data and generating precise answers is a complex task. This demo solves the problem by:
- Persisting embeddings in a vector database (Qdrant) for faster future access.
- Combining semantic search with generative AI for accurate, context-aware responses.
- Allowing reuse of processed data sources across multiple sessions.
π» Sample Application Description
This is a console-based chatbot demo that loads a series of eBooks, stores their embeddings in a local Qdrant instance, and uses RAG to answer queries.
β¨ Key Features
- π Qdrant Integration: Uses LM-Kit.NET.Data.Connectors.Qdrant to persist embeddings locally.
- π¦ Model Loading: Load chat and embedding models from predefined URLs or custom paths.
- π§ Persistent Vector Store: Avoid redundant embedding computation across sessions.
- π Semantic Search: Retrieve relevant content chunks before generation.
- π Performance Tracking: Measure data source loading time.
- β»οΈ Cached Data Handling: Reuse indexed vectors when available.
π§ Supported Models
- Chat Model: Gemma 3.4B Instruct (quantized variant)
- Embeddings Model: BGE-small-en-v1.5
π§Ύ Data Sources
Three classic eBooks are loaded as semantic knowledge bases:
- Romeo and Juliet by William Shakespeare
- Moby Dick by Herman Melville
- Pride and Prejudice by Jane Austen
π οΈ Getting Started
π Prerequisites
- .NET 6.0 SDK
- Qdrant Vector DB (local setup)
- Docker (for running Qdrant locally)
π§° Qdrant Setup
Run Qdrant locally using Docker:
docker run -p 6333:6333 -p 6334:6334 qdrant/qdrant
π₯ Download the Project
βΆοΈ Run the Application
- π Clone the repository:
git clone https://github.com/LM-Kit/lm-kit-net-samples.git
- π Navigate to the demo directory:
cd lm-kit-net-samples/console_net/custom_chatbot_with_rag_qdrant_vector_store
- π¨ Build and run:
dotnet build
dotnet run
π¬ Example Usage
- Load both models (chat and embedding) from URLs or specify local paths.
- The demo will load the eBooks, embedding them via LM-Kit and storing them in Qdrant.
- Enter your query, e.g.:
"Who are the main characters in Romeo and Juliet?"
"What is Captain Ahabβs goal in Moby Dick?"
- The chatbot retrieves matching content and generates a response.
- The app skips re-embedding if the data is already present in Qdrant.
π οΈ Special Behavior
- β Reuse of stored collections: Embeddings are reused if already indexed.
- π Fresh vector indexing: If a collection is not present, itβs created and persisted.
- π Dynamic top-k: GPU-optimized systems select more partitions for improved accuracy.
π Licensing
To run the application, you can use a free community license available at:
π https://lm-kit.com/products/community-edition/
π Related Repositories
- Demo source code (.NET 6.0): custom_chatbot_with_rag_qdrant_vector_store
- Qdrant Connector Assembly (Open Source): LM-Kit.NET.Data.Connectors.Qdrant
By combining the power of semantic search and LLMs, this demo offers a robust foundation for building production-ready, intelligent chatbots in C# with persistent, scalable vector storage.