This project is a localized Retrieval-Augmented Generation (RAG) system that allows users to store personal profiles or documents and query them using a Large Language Model (LLM). It uses a local vector database for storage and a local LLM for generating answers, ensuring data privacy and low latency.
The application provides a REST API to:
- Store Documents: Accept text content (like personal profiles), split it into manageable chunks, and store them in a vector database with associated metadata.
- Contextual Search: Retrieve the most relevant pieces of information from the database based on a user's question.
- Local AI Generation: Use the retrieved context to answer questions accurately using a local LLM, filtering by specific users if requested.
- Static Embedding: Includes a script (
embed.py) to quickly ingest specific files (likek8s.txt) into the vector store.
- FastAPI: A modern, high-performance web framework for building APIs with Python.
- ChromaDB: An open-source embedding database (vector store) used to store and search document chunks.
- Ollama: A platform for running LLMs locally.
- Embedding Model:
nomic-embed-textfor converting text into vector representations. - Chat Model:
tinyllamafor generating answers based on retrieved context.
- Embedding Model:
- Pydantic: Used for data validation and settings management within the API.
app.py: The main FastAPI application containing the/documents(POST) and/ask(GET) endpoints.embed.py: A utility script to manually embed text files (e.g.,k8s.txt) into the database.db/: Local directory where ChromaDB persists its data.k8s.txt: Sample text file used for static embedding.
- Install Ollama: Ensure Ollama is installed and running.
- Pull Models:
ollama pull nomic-embed-text ollama pull tinyllama
- Set up a virtual environment:
python -m venv venv source venv/bin/activate - Install dependencies:
pip install fastapi ollama chromadb uvicorn
Start the API server:
uvicorn app:app --reload- POST
/documents: Send a JSON body withuser_nameandcontentto store data. - GET
/ask: Query the system using aquestionparameter (optionaluserfilter available).