Skip to content
Zengineer.cloud logo
Zengineer.cloud
Get in Touch
  • Home
  • Blog
  • Projects
  • Contact
Company
  • About
  • Contact
Work
  • Projects
  • Blog
Legal
  • Privacy
  • Terms

© 2025 Zengineer.cloud & Ben Hickman

Building a Private AI Knowledge Assistant Using Open Source LLMs and LangChain

Building a Private AI Knowledge Assistant Using Open Source LLMs and LangChain

Building a Private AI Knowledge Assistant Using Open Source LLMs and LangChain

In this project, I built a Retrieval-Augmented Generation (RAG) application from the ground up using modern open-source large language models like Mistral-7B-Instruct, combined with a full suite of AI infrastructure tools. The result is a private, self-hosted assistant capable of reasoning over your own documents securely and efficiently.

Tech Stack Overview

Here’s a breakdown of the main technologies and libraries that power the system.

Core Libraries and Frameworks
LangChain serves as the foundation of the RAG pipeline, providing modular components for agents, chains, retrievers, and prompt templates. Hugging Face Transformers handles model loading and inference, running open-source models such as Mistral-7B through the AutoModelForCausalLM and AutoTokenizer APIs. Sentence-Transformers is used to create high-quality embeddings for semantic retrieval. The combination of Torch, Accelerate, and BitsAndBytes ensures efficient inference, especially for large quantized models.

Vector Database and Retrieval
ChromaDB is used for storing and retrieving embedded text chunks with fast similarity search. In environments without GPU access, FAISS-CPU can be used as a fallback for vector similarity search.

Document Processing and Parsing
Unstructured manages parsing of complex document formats like PDFs and HTML into clean text chunks. Libraries such as PyPDF and python-docx handle structured extraction, while Tiktoken ensures token-aware chunking and cost estimation for model queries.

Data Handling
Pandas and NumPy manage preprocessing, metadata tagging, and diagnostics, while Python-dotenv keeps environment variables and model configurations clean and consistent across environments.

User Interface
Streamlit powers the user interface, providing a simple way to upload documents, ask natural-language questions, and view AI-generated answers along with their source citations—all without needing to write code.

How It Works

Document Ingestion: Uploaded files are parsed into raw text using Unstructured, PyPDF, and python-docx. The text is split into token-aware chunks, then encoded into embeddings using Sentence-Transformers.

Storage and Indexing: The embeddings are stored in ChromaDB with metadata such as file name and source path to maintain traceability.

Query Processing: When a user submits a question, the system performs a vector search to find the most relevant text chunks. These chunks are combined with the question in a structured prompt and sent to an LLM, such as Mistral-7B. The model generates a clear, contextual response that includes source citations.

LLM Hosting: Models can be run locally through Transformers with support for accelerated or quantized inference. The app also supports switching models via configuration, making it easy to test different local or hosted models, including those from Hugging Face or Replicate.

Highlights

Built for self-hosting and private data use

Includes a complete RAG pipeline with semantic chunking and retrieval

Modular structure allowing interchangeable LLMs, vector databases, and embedding models

Prompt engineering optimized for clarity and reliability

Privacy-first design suitable for legal, healthcare, or enterprise contexts

What I Learned

This project gave me hands-on experience across the full generative AI stack, including:

Implementing and tuning vector search systems

Designing effective prompts for retrieval-augmented responses

Running and optimizing large models efficiently through quantization

Building quick frontends with Streamlit for prototyping and testing

Structuring modular, reusable AI components

Final Thoughts

With open-source tools like LangChain, Hugging Face, ChromaDB, and Streamlit, it’s possible to build powerful AI assistants that remain private, explainable, and adaptable. This project demonstrates how retrieval and generation can work together to create practical, privacy-respecting AI systems ready for real-world use.