CI: see .github/workflows/ci.yml. Currently a stub workflow (real pytest job blocked on NOES-54). Branch protection on main requires CI pass before merge β admin (rsync deploy) can still push directly.
This project implements a production-ready Retrieval-Augmented Generation (RAG) assistant using LangChain, FAISS, and three model options: Mixtral (GGUF), LLaMA3 (Hugging Face Transformers), and GPT-4o (OpenAI). It supports both CLI and FastAPI interfaces for real-time question answering over embedded documents.
β Designed for technical interviews, enterprise search, or AI assistant prototyping β fully offline-capable and extensible.
π Platform: This system is built on a local machine to avoid cloud compute costs. However, it can be easily transported to any cloud such as AWS, GCP, or Azure. To run locally requires a rather beefy workstation/server. I developed it using a system with the following specs:
- CPU: Threadripper 64 Core, 128 Threads
- Memory: 512 GB DDR5
- Disk: 20 TB NVMe SSD
- GPU: Two Nvidia A6000 GPUs
- π RAG architecture: combines retrieval + generation for grounded, explainable answers.
- π€ Local LLM inference: runs via
llama.cppor Hugging Face Transformers. - π§ Semantic vector search: uses
sentence-transformersandFAISS. - π FastAPI backend: exposes
/askand/rebuildendpoints with JSON responses. - πͺ Session memory: persists chat history in PostgreSQL.
- π Document ingestion: supports
.pdf,.docx, and.txtfiles via directory-based loader. - π§ͺ Swagger docs: self-documenting API.
- π Offline mode: models can run fully locally with no external API dependencies.
- π’ Token estimation: optional for local models like LLaMA3 and Mixtral.
- π§Ύ Model logging: API metadata includes model used and latency.
βββ app
β βββ agents
β β βββ doc_agent.py
β β βββ orchestrator.py
β βββ chains
β β βββ qa_chain.py
β βββ configs
β β βββ llm_config.yaml
β β βββ pdf_tags.yml
β β βββ prompts
β βββ embeddings
β β βββ embedder.py
β βββ interface
β β βββ __pycache__
β β β βββ query_eval.cpython-310.pyc
β β β βββ query_plus.cpython-310.pyc
β β βββ query_eval.py
β β βββ query_plus.py
β β βββ query.py
β βββ llm_core.py
β βββ loaders
β β βββ fhir_loaders.py
β βββ retrievers
β β βββ vector_retriever.py
β βββ tagging
β β βββ semantic_tagger.py
β βββ tools
β β βββ __pycache__
β β β βββ summarize.cpython-310.pyc
β β βββ summarize.py
β βββ vectorstore
β βββ chunk_db.json
β βββ index.faiss
β βββ index.pkl
βββ chat
β βββ postgres_history.py
β βββ __pycache__
β β βββ postgres_history.cpython-310.pyc
β β βββ vectorstore_memory.cpython-310.pyc
β βββ vectorstore_memory.py
βββ config.py
βββ data
β βββ csv
β βββ docs
β β βββ rag_explained.txt
β βββ json
β βββ kindle
β βββ pdfs
β β βββ π¬
β βββ text
βββ eval
β βββ eval_queries.json
β βββ eval_queries.jsonl
βββ LICENSE
βββ main.py
βββ models
β βββ download_mixtral.py
β βββ llama3-8b
β β βββ π¬
β βββ mistral-7b
β β βββ π¬
β βββ mixtral-8x7b
β β βββ π¬
β βββ mixtral-gguf
β β βββ π¬
β βββ model_test.py
βββ rag_api
βββ rag_api_service.py
βββ README.md
βββ rebuild_vs.py
βββ requirements.txt
βββ search_vectorstore.py
βββ test.py
βββ vectorstore
βββ index.faiss
βββ index.pkl
conda activate genai-core
pip install -r requirements.txt
pip install sentencepieceDrop your .pdf, .docx, or .txt files into data/ (or subfolders).
Then run:
python rebuild_vs.pyThis rebuilds the FAISS vector index with semantic embeddings using sentence-transformers.
python app/interface/query_plus.py "What is RAG?" --model mixtral --chat --session-id demo1Options:
--model mixtral|llama3|gpt4o--filter-tagor--filter-filefor scoped retrieval--chatenables persistent memory--session-idgroups chats by user
Start the API:
uvicorn rag_api_service:app --reloadVisit Swagger docs:
http://127.0.0.1:8000/docs
Example POST to /ask:
{
"query": "What is retrieval-augmented generation?",
"session_id": "test1",
"model": "llama3",
"token_estimate": true
}Response includes:
-
answer -
sources[]: source text chunks -
meta:elapsed_secondstokens_estimatedmodel
Prompts are dynamically constructed using:
- Retrieved chunks (
similarity_search_with_score) - Optional session memory
- Custom headers: "You are an AI document analyst..."
You can customize this in generate_prompt() inside query_plus.py.
- Mixtral: GGUF model run via
llama.cpp(fast, parallelized on GPU) - LLaMA 3 8B: Hugging Face Transformers model running in FP16 on GPU
- GPT-4o: OpenAI fallback using API + YAML config
To use OpenAI:
export OPENAI_API_KEY=sk-...Chat logs are stored in chathist.chat_history:
session_id,role,content,created_at- Used for session memory and context carryover
Uses .pgpass for secure auth (no credentials in code).
API responses include:
elapsed_seconds: total inference + retrieval timetokens: OpenAI usage count if applicabletokens_estimated: estimated using tokenizer for local modelsmodel: which LLM handled the request
| Model | Latency (s) | Local | Token Usage | Notes |
|---|---|---|---|---|
| Mixtral | ~2.7 | β Yes | estimated | Fast + multi-GPU (llama.cpp) |
| LLaMA3-8B | ~11.2 | β Yes | estimated | HuggingFace, accurate, slower |
| GPT-4o | ~1.5β2.5 | β API | exact via API | Fastest, but external dependency |
| Tool | Command |
|---|---|
| Search vectorstore | python search_vectorstore.py "your query" |
| Rebuild index | python rebuild_vs.py |
| API query | curl -X POST http://127.0.0.1:8000/ask ... |
Set local_files_only=True in AutoTokenizer and AutoModelForCausalLM to enforce offline mode.
- β Swagger-enabled API
- β Chat memory with PostgreSQL
- β LLaMA 3 support via Transformers
- β Token estimation for local models
- β Model logging in metadata
- β³ User auth or API key guardrails
- β³ Vectorstore auto-refresh with S3 uploads
- β³ Web frontend (Streamlit or React)
- β³ GCP Cloud Run deployment config
Randall Shane β LinkedIn
Senior AI/ML Systems Architect with 20+ years of experience designing scalable, production-grade platforms across healthcare, finance, and enterprise analytics. Most recently led end-to-end GenAI and retrieval-augmented generation (RAG) development using LangChain, FAISS, and OpenAI/GCP models.
This repository reflects my current focus: building secure, modular, and extensible GenAI pipelines that combine local and cloud-hosted LLMs with vector search, prompt engineering, and human-in-the-loop evaluation. I lead senior-level roles in AI/ML engineering or GenAI systems design, particularly where intelligent assistants and clinical/niche use cases are a focus.