Personal AI Assistant with RAG (Hugging Face Edition)
A powerful personal AI assistant built with LangChain, integrating Retrieval-Augmented Generation (RAG) with a vector database (Qdrant) for improved contextual awareness and memory. This version uses Hugging Face models and can be deployed to Hugging Face Spaces for free hosting.
Features
- Large Language Model integration using Hugging Face's free models
- RAG-based memory system with vector database storage
- Document ingestion pipeline for various file types
- Simple web UI built with Streamlit
- Conversation history tracking and retrieval
- Free deployment on Hugging Face Spaces
Project Structure
.
βββ README.md
βββ requirements.txt
βββ .env.example
βββ app.py # Main entry point for Hugging Face Spaces
βββ space.py # Hugging Face Spaces SDK integration
βββ app/
β βββ main.py # FastAPI application entry point
β βββ config.py # Configuration settings
β βββ ui/
β β βββ streamlit_app.py # Streamlit web interface
β βββ core/
β β βββ llm.py # LLM integration (Hugging Face)
β β βββ memory.py # RAG and vector store integration
β β βββ agent.py # Agent orchestration
β β βββ ingestion.py # Document processing pipeline
β βββ utils/
β βββ helpers.py # Utility functions
βββ data/
βββ documents/ # Store for uploaded documents
βββ vector_db/ # Local vector database storage
Setup
- Clone this repository
- Install dependencies:
pip install -r requirements.txt
- Copy
.env.example
to.env
and fill in your Hugging Face API keys (optional) - Start the Streamlit UI:
streamlit run app/ui/streamlit_app.py
Usage
- Upload documents through the web interface
- Chat with your assistant, which can now reference your documents
- The assistant will automatically leverage your document knowledge to provide more personalized responses
Deployment to Hugging Face Spaces
This app can be easily deployed to Hugging Face Spaces for free hosting:
- Create a Hugging Face account at huggingface.co
- Set environment variables:
export HF_USERNAME=your-username export HF_TOKEN=your-huggingface-token export SPACE_NAME=personal-rag-assistant # optional
- Run the deployment script:
python space.py
- Visit your deployed app at
https://huggingface.co/spaces/{your-username}/{space-name}
Alternatively, you can manually create a new Space on Hugging Face and link it to your GitHub repository.
Models Used
This implementation uses the following free models from Hugging Face:
- LLM: google/flan-t5-large - A powerful instruction-tuned model
- Embeddings: sentence-transformers/all-MiniLM-L6-v2 - Efficient embedding model
You can change these in the .env
file.
Extending
- Add more document loaders in
ingestion.py
- Integrate additional tools in
agent.py
- Customize the UI in
streamlit_app.py
- Switch to a different LLM in
llm.py
and.env