Prerequisites
Install Required Dependencies
Python 3.10 or newer is required.Step 1: Set API Keys (Optional)
Note: By default, the server runs in development mode (no authentication) when neitherAPI_KEYS nor JWT_SECRET is set. If you have HuggingFace models installed, the server works without provider keys. Provider keys are only needed for OpenAI or Anthropic models.
Option A: Windows PowerShell (Temporary - Current Session Only)
Option B: Windows Command Prompt (Temporary - Current Session Only)
Option C: Create .env file
Create a file named.env in the directory you start the server from:
.env from the current working directory automatically (python-dotenv is a core dependency, loaded by multimind.core.config). Variables already set in the shell take precedence.
Note: If you don’t set any API keys, the server will automatically use local HuggingFace models (requires transformers and torch installed).
Step 2: Verify API Key is Set (If Using API Keys)
In PowerShell:
In Command Prompt:
Step 2.1: Configure JWT/Auth Security Variables (.env)
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).
Required/Optional fields
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
1) Generate JWT_SECRET
PowerShell:
2) Generate bcrypt password hash
Install passlib+bcrypt (if needed):3) Set JWT_USERS_JSON
Use the generated hash in JSON (single line):
4) Optional API_KEYS
Example secure .env block
- 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.
Step 3: Start the RAG API Server
Method 1: Run as module (RECOMMENDED)
Method 2: Using uvicorn directly
Method 3: Combined MultiMind API
python multimind/gateway/rag_api.py directly - it will fail with ImportError!
Step 4: Verify Server is Running
You should see uvicorn start:- API Documentation: http://localhost:8000/docs
- Health Check: http://localhost:8000/health (
/readyreturns 503 until the backend has been initialized)
Step 5: Test with Client Example
Open a NEW terminal window (keep server running in first terminal):api_key=None in the client:
Model Selection Priority
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 - Embeddings: the server still configures OpenAI
text-embedding-ada-002(dimension 1536) because Anthropic has no embedding models, but withoutOPENAI_API_KEYthe embedding client cannot be created and initialization fails with503 "RAG backend is not available". - ⚠️ In practice, Anthropic-only setups need
OPENAI_API_KEYas well, or unsetANTHROPIC_API_KEYto fall through to the local HuggingFace option and switch the text model afterwards withPOST /models/switch.
- 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:
Troubleshooting
Error: “No model API keys found”
- 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)
Error: “Cannot connect to host localhost:8000”
- 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
Error: “Module not found” or “ImportError”
- Install the extras:
pip install "multimind-sdk[gateway,rag]" - Use
python -m multimind.gateway.rag_api(with-mflag), not direct file execution
Error: “FAISS is not available”
- Install FAISS:
pip install faiss-cpu(included in theragextra; orfaiss-gpuif you have CUDA) - FAISS is required for the vector store
Error: “HuggingFace models not available”
- Install:
pip install transformers torch sentence-transformers - Models will download automatically on first use (stored in
~/.cache/huggingface/)
Error: “Authentication required”
- In development mode, this shouldn’t happen if neither
API_KEYSnorJWT_SECRETis set - If you set
API_KEYS, you need to provide a valid API key in the client (or a JWT whenJWT_SECRETis set) - Remove both variables for development mode
Error: “JWT authentication is not configured” (503 from /token)
- Set
JWT_SECRETandJWT_USERS_JSON(Step 2.1) and installpasslib[bcrypt]
API Endpoints
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
Available Endpoints
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- Liveness check (no auth)GET /ready- Readiness check (503 until the RAG backend is initialized)POST /token- Get JWT token (for authentication)
Example API Calls
Using curl (PowerShell):
Development Mode vs Production Mode
Development Mode (No Authentication)
- By default when neither
API_KEYSnorJWT_SECRETis 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 provider keys are provided
Production Mode (With Authentication)
- Set
API_KEYSenvironment variable → Authentication required - Provide API key in client →
RAGClient(api_key="your-key") - Or set
JWT_SECRET+JWT_USERS_JSONand use/tokenbearer tokens (RAGClient(token=...)orawait client.login(...)) - There is no rate limiting; put the server behind a reverse proxy with TLS
Summary
- Install dependencies:
pip install "multimind-sdk[gateway,rag]" - Optional: Set
OPENAI_API_KEYorANTHROPIC_API_KEY(or use local HuggingFace models) - Start server:
python -m multimind.gateway.rag_api(ormultimind backendfor the combined API) - Test client:
python examples/client/rag_client_example.py - Access docs: http://localhost:8000/docs
