A personal knowledge base application using FastAPI, Milvus, and Gemini for storing and retrieving information using RAG (Retrieval Augmented Generation).
- Store questions and answers with vector embeddings
- Query the knowledge base using natural language
- Stream responses for real-time interaction
- Vector similarity search using Milvus
- RAG-powered responses using Gemini
- Python 3.8+
- Milvus server running locally or accessible
- Gemini API key
app/
├── __init__.py
├── main.py
├── config.py
├── routes/
│ ├── __init__.py
│ ├── health.py
│ └── knowledge.py
└── services/
├── __init__.py
├── milvus_service.py
└── gemini_service.py
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Set up environment variables:
Create a
.envfile with the following variables:
# Milvus Configuration
MILVUS_HOST=localhost
MILVUS_PORT=19530
MILVUS_COLLECTION_NAME=second_brain
# Gemini Configuration
GEMINI_API_KEY=your_gemini_api_key_here
# Vector Configuration
VECTOR_DIMENSION=768
VECTOR_INDEX_TYPE=IVF_FLAT
VECTOR_METRIC_TYPE=COSINEStart the server using uvicorn:
uvicorn app.main:app --reloadThe application will be available at:
- http://localhost:8000
- API documentation: http://localhost:8000/docs
- GET
/health- Check application health
- POST
/knowledge/add- Add a new document (question and answer) - POST
/knowledge/query- Query the knowledge base - POST
/knowledge/query/stream- Stream the response from querying
- Add a document:
curl -X POST "http://localhost:8000/knowledge/add" \
-H "Content-Type: application/json" \
-d '{"question": "What is Python?", "answer": "Python is a high-level programming language..."}'- Query the knowledge base:
curl -X POST "http://localhost:8000/knowledge/query" \
-H "Content-Type: application/json" \
-d '{"question": "Tell me about Python"}'- Stream query response:
curl -X POST "http://localhost:8000/knowledge/query/stream" \
-H "Content-Type: application/json" \
-d '{"question": "Tell me about Python"}'