REST API for RAG over Star Trek MemoryAlpha database using Ollama
970
A REST API for Retrieval-Augmented Generation (RAG) over Star Trek's MemoryAlpha database using Ollama and FastAPI.
This project provides a REST API that enables natural language queries over the comprehensive Star Trek MemoryAlpha database. It uses the vectorized database from memoryalpha-vectordb and combines it with local LLMs via Ollama to provide accurate, context-aware responses about Star Trek lore.
The system implements:
Clone and start the services:
git clone https://github.com/aniongithub/memoryalpha-rag-api.git
cd memoryalpha-rag-api
docker-compose build
docker-compose up
Wait for initialization: The first startup will download the Ollama model and ML models for reranking. This may take several minutes.

Start chatting:
./chat.sh
Example queries:
"What is a transporter?"
"Tell me about Captain Picard"
"How does warp drive work?"
"What happened in the Dominion War?"

GET /memoryalpha/healthGET or POST /memoryalpha/rag/ask — returns the complete answer as JSONGET or POST /memoryalpha/rag/stream — streams the answer as text/plain chunksThe host port defaults to
8000but is configurable viaAPI_PORTin.env(the container always listens on8000). Adjust the URLs below to match yourAPI_PORT.
curl "http://localhost:8000/memoryalpha/rag/ask?question=What%20is%20a%20Transporter?&max_tokens=512&top_k=10&top_p=0.8&temperature=0.3"
curl -N "http://localhost:8000/memoryalpha/rag/stream?question=What%20is%20the%20Enterprise?&max_tokens=512&top_k=10"
curl "http://localhost:8000/memoryalpha/rag/ask?question=What%20is%20a%20Transporter?&use_tools=true"
The system uses the following environment variables (set in .env):
# Ollama Configuration
OLLAMA_URL=http://ollama:11434
DEFAULT_MODEL=qwen3:0.6b-q4_K_M
# Database Configuration
DB_PATH=/data/enmemoryalpha_db
TEXT_COLLECTION_NAME=memoryalpha_text
# API Configuration
API_PORT=8000
MAX_TOKENS=2048
TOP_K=10
question: Your Star Trek questionmax_tokens: Maximum response length (default: 2048)top_k: Number of documents to retrieve (default: 10)top_p: Sampling parameter (default: 0.8)temperature: Response creativity (default: 0.3)use_tools: Use the legacy tool-calling agent loop instead of single-pass RAG (default: false; /ask only)This project includes a complete development environment using VS Code Dev Containers:
Install prerequisites:
Open in Dev Container:
Ctrl+Shift+P (or Cmd+Shift+P on Mac)Development features:
For more information on Dev Containers, see the VS Code Dev Containers Tutorial.
If you prefer local development without containers:
pip install -r requirements.txt
# Install Ollama (see https://ollama.ai)
ollama pull qwen3:0.6b-q4_K_M
wget https://github.com/aniongithub/memoryalpha-vectordb/releases/latest/download/enmemoryalpha_db.tar.gz
tar -xzf enmemoryalpha_db.tar.gz
uvicorn api.main:app --host 0.0.0.0 --port 8000 --reload
graph TD
A[User Query] --> B[FastAPI + RAG Pipeline]
B --> C[Document Retrieval]
C --> D[ChromaDB Vector Database<br/>MemoryAlpha Data]
B --> E[Cross-Encoder Reranking]
B --> F[Ollama + LLM]
F --> G[Streaming Response]
style A fill:#e1f5fe
style B fill:#f3e5f5
style D fill:#e8f5e8
style F fill:#fff3e0
style G fill:#fce4ec
./chat.shThis project is licensed under the MIT License - see the LICENSE file for details.
Content type
Image
Digest
sha256:6a82ede90…
Size
739.2 MB
Last updated
about 2 months ago
docker pull aniondocker/memoryalpha-rag-api