# Install core dependencies
pip install PyJWT fastapi uvicorn
# Install FAISS for vector store (required)
pip install faiss-cpu
# OR if you have CUDA GPU:
# pip install faiss-gpu
# Optional: For local HuggingFace models (if no API keys)
pip install transformers torch sentence-transformersNote: By default, the server runs in development mode when API_KEYS is not set. If you have HuggingFace models installed, the server works without API keys. API keys are only needed for OpenAI or Anthropic models.
# For OpenAI
$env:OPENAI_API_KEY="your-actual-openai-api-key-here"
# OR for Anthropic
$env:ANTHROPIC_API_KEY="your-actual-anthropic-api-key-here"# For OpenAI
set OPENAI_API_KEY=your-actual-openai-api-key-here
# OR for Anthropic
set ANTHROPIC_API_KEY=your-actual-anthropic-api-key-hereCreate a file named .env in your project root:
OPENAI_API_KEY=your-actual-openai-api-key-here
# OR
ANTHROPIC_API_KEY=your-actual-anthropic-api-key-here
.env files. To use a .env file:
- Install python-dotenv:
pip install python-dotenv - Load it in your code before running the server, OR
- Use environment variables directly (Option A or B above)
Note: If you don't set any API keys, the server will automatically use local HuggingFace models (requires transformers and torch installed).
echo $env:OPENAI_API_KEY
# OR
echo $env:ANTHROPIC_API_KEYecho %OPENAI_API_KEY%
# OR
echo %ANTHROPIC_API_KEY%You should see your API key printed. If nothing shows, the server will use local HuggingFace models.
If you want to use /token JWT auth (production-style), add these values to your .env.
This matches .env.example (API_KEYS, JWT_SECRET, JWT_USERS_JSON).
API_KEYS(optional): comma-separated API keys forX-API-KeyauthJWT_SECRET(required for/token): long random secret (32+ chars)JWT_USERS_JSON(required for/token): JSON mapping username -> bcrypt hash
PowerShell:
python -c "import secrets; print(secrets.token_urlsafe(48))"Copy output into:
JWT_SECRET=your_generated_secret_hereInstall passlib+bcrypt (if needed):
pip install passlib[bcrypt]Generate hash:
python -c "from passlib.context import CryptContext; c=CryptContext(schemes=['bcrypt'], deprecated='auto'); print(c.hash('YourStrongPassword123!'))"Use the generated hash in JSON (single line):
JWT_USERS_JSON={"admin":"$2b$12$replace_with_bcrypt_hash","testuser":"$2b$12$replace_with_bcrypt_hash"}API_KEYS=key_one,key_two,key_threeOPENAI_API_KEY=your-openai-key
API_KEYS=internal_key_1,internal_key_2
JWT_SECRET=replace_with_long_random_secret_32plus_chars
JWT_USERS_JSON={"admin":"$2b$12$replace_with_bcrypt_hash"}Important:
- Do not commit real secrets to git.
- Do not use default/fallback secrets in production.
- If
JWT_SECRET/JWT_USERS_JSONare missing,/tokenauth should be considered not securely configured.
# Navigate to your project directory (where multimind-sdk is located)
cd your-project-directory\multimind-sdk
# Run the server (MUST use -m flag for relative imports to work)
python -m multimind.gateway.rag_apiuvicorn multimind.gateway.rag_api:app --host 0.0.0.0 --port 8000python multimind\gateway\rag_api.py directly - it will fail with ImportError!
You should see output like:
📋 Checking for API keys...
OPENAI_API_KEY: ❌ Not found
ANTHROPIC_API_KEY: ❌ Not found
============================================================
✅ RAG SYSTEM INITIALIZED SUCCESSFULLY
============================================================
📊 Provider: HuggingFace (Local)
📝 Text Model: gpt2
🔤 Embedding Model: sentence-transformers/all-MiniLM-L6-v2
📦 Vector Store: FAISS
============================================================
INFO: Started server process
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000
Open your browser and go to:
- API Documentation: http://localhost:8000/docs
- Health Check: http://localhost:8000/health
Open a NEW terminal window (keep server running in first terminal):
# Navigate to your project directory (where multimind-sdk is located)
cd your-project-directory\multimind-sdk
# Run the client example (no API key needed in development mode)
python examples\client\rag_client_example.pyNote: In development mode, you can remove or set api_key=None in the client:
client = RAGClient(
base_url="http://localhost:8000"
# No api_key needed in development mode
)The server automatically selects models in this order:
-
OpenAI (if
OPENAI_API_KEYis set)- Text Model:
gpt-3.5-turbo - Embedding Model:
text-embedding-ada-002 - Dimension: 1536
- Text Model:
-
Anthropic (if
ANTHROPIC_API_KEYis set, but no OpenAI key)- Text Model:
claude-3-sonnet-20240229✅ (Anthropic provides this) - Embeddings:
⚠️ Anthropic does NOT provide embedding models- Requires one of the following:
- OpenAI embeddings (
text-embedding-ada-002) - needsOPENAI_API_KEY - OR HuggingFace local embeddings (
sentence-transformers/all-MiniLM-L6-v2) - no API key needed
- OpenAI embeddings (
- Dimension: 1536 (if using OpenAI) or 384 (if using HuggingFace)
⚠️ Important: Anthropic only provides text generation, not embeddings
- Text Model:
-
HuggingFace Local (if no API keys are set)
- Text Model:
gpt2 - Embedding Model:
sentence-transformers/all-MiniLM-L6-v2 - Dimension: 384
- ✅ No API keys required - runs completely locally
- Models download automatically on first use
- Text Model:
- Solution 1: Set
OPENAI_API_KEYorANTHROPIC_API_KEYenvironment variable - Solution 2: Install HuggingFace models:
pip install transformers torch sentence-transformers - Restart your terminal after setting environment variables
- Verify with
echo $env:OPENAI_API_KEY(PowerShell) orecho %OPENAI_API_KEY%(CMD)
- Make sure the server is running (Step 3)
- Check if port 8000 is already in use
- Try accessing http://localhost:8000/health in browser
- Make sure you're using the correct URL in the client
- Make sure you're in the project directory
- Install dependencies:
pip install PyJWT fastapi uvicorn - Use
python -m multimind.gateway.rag_api(with-mflag), not direct file execution
- Install FAISS:
pip install faiss-cpu(orfaiss-gpuif you have CUDA) - FAISS is required for the vector store
- Install:
pip install transformers torch sentence-transformers - Models will download automatically on first use (stored in
~/.cache/huggingface/)
- In development mode, this shouldn't happen if
API_KEYSenvironment variable is not set - If you set
API_KEYS, you need to provide a valid API key in the client - Remove
API_KEYSenvironment variable for development mode
Once running, you can access:
- Swagger UI (Interactive Docs): http://localhost:8000/docs
- ReDoc (Alternative Docs): http://localhost:8000/redoc
- Health Check: http://localhost:8000/health
POST /documents- Add documents to the RAG systemPOST /files- Upload and add filesPOST /query- Query documentsPOST /generate- Generate responses using RAGDELETE /documents- Clear all documentsGET /documents/count- Get document countPOST /models/switch- Switch text generation modelGET /health- Health checkPOST /token- Get JWT token (for authentication)
# Health check
curl http://localhost:8000/health
# Add documents
curl -X POST http://localhost:8000/documents `
-H "Content-Type: application/json" `
-d '{\"documents\":[{\"text\":\"Test document\",\"metadata\":{}}]}'
# Query
curl -X POST http://localhost:8000/query `
-H "Content-Type: application/json" `
-d '{\"query\":\"What is the RAG system?\",\"top_k\":3}'
# Generate response
curl -X POST http://localhost:8000/generate `
-H "Content-Type: application/json" `
-d '{\"query\":\"Explain the RAG system\",\"temperature\":0.7}'- By default when
API_KEYSenvironment variable is NOT set → All requests allowed - No API keys needed in client → Works without authentication
- Perfect for local testing and development
- Server automatically uses HuggingFace local models if no API keys are provided
- Set
API_KEYSenvironment variable → Authentication required - Provide API key in client →
RAGClient(api_key="your-key") - Use JWT tokens for more secure authentication
- Install dependencies:
pip install PyJWT fastapi uvicorn faiss-cpu - Optional: Set
OPENAI_API_KEYorANTHROPIC_API_KEY(or use local HuggingFace models) - Start server:
python -m multimind.gateway.rag_api - Test client:
python examples\client\rag_client_example.py - Access docs: http://localhost:8000/docs
The server automatically detects available models and uses the best option available!