Faniyi/Apextech-knowledge-base
๐ข ApexTech Solutions โ Company Knowledge Base
An internal AI-powered assistant that allows ApexTech employees to query company documentation using natural language. Built with RAG (Retrieval-Augmented Generation), it retrieves relevant information from internal documents and generates accurate, sourced answers.
๐๏ธ Architecture
Query
โ
โผ
Query Rewriter (gpt-4o-mini) โ Rewrites vague/conversational queries
โ
โผ
Hybrid Search โ Dense (Chroma) + Sparse (BM25) fused via RRF
โ
โผ
Cross-Encoder Reranker โ ms-marco-MiniLM-L-6-v2 reranks top-k chunks
โ
โผ
LLM (gpt-4.1-mini) + System Prompt โ Grounded answer from retrieved context
โ
โผ
Answer + Sources๐ Project Structure
company-knowledge-base/
โโโ UI/
โ โโโ ui.py # Chainlit UI (User mode)
โโโ rag/
โ โโโ answer.py # Full RAG pipeline
โ โโโ hybrid_search.py # Dense + BM25 + RRF + cross-encoder reranker
โ โโโ query_rewriter.py # LLM query rewriter
โ โโโ ingest.py # Document ingestion
โ โโโ chunking.py # Text splitting
โ โโโ embedding.py # HuggingFace embeddings
โ โโโ vectorstore.py # Chroma vector store
โโโ llm/
โ โโโ llm.py # LLM initialisation
โ โโโ prompt.py # System prompt template
โโโ evals/
โ โโโ datasets/
โ โ โโโ qa_dataset.json # 60 QA pairs (easy + hard)
โ โ โโโ edge_cases.json # 20 adversarial / edge cases
โ โโโ metrics/
โ โ โโโ retrieval_metrics.py # recall@k, precision@k, MRR
โ โ โโโ generation_metrics.py # faithfulness, relevance, correctness
โ โ โโโ context_metrics.py # context coverage, context relevance
โ โ โโโ e2e_metrics.py # task success, unanswerable awareness, CI gates
โ โโโ runners/
โ โ โโโ run_evals.py # local + ci modes with LangSmith integration
โ โโโ results/ # Timestamped JSON eval reports
โโโ data/
โ โโโ raw/ # Source .md documents (canonical)
โ โโโ vector_db/ # Chroma persistent store
โโโ main.py # Entry point โ ingest check + UI launch
โโโ chainlit.md # Chainlit welcome screen๐ Getting Started
1. Clone the repository
git clone https://github.com/faniyi-akinbobola/company-knowledge-base.git
cd company-knowledge-base2. Install dependencies
uv sync3. Set up environment variables
cp .env.example .envEdit .env:
OPENAI_API_KEY=sk-...
LANGCHAIN_TRACING_V2=true
LANGCHAIN_API_KEY=lsv2_...
LANGCHAIN_PROJECT=company-knowledge-base4. Run the app
uv run python main.pyThis will:
- โ Check if the vector store exists
- โ Auto-ingest documents if not found
- โ
Launch the Chainlit UI at
http://localhost:8000
๐งช Evals
# Fast local run โ no LLM judge
uv run python evals/runners/run_evals.py --mode local
# With LLM-as-judge (faithfulness, correctness, relevance, hallucination)
uv run python evals/runners/run_evals.py --mode local --llm-judge
# CI mode โ requires LANGCHAIN_API_KEY, exits with code 1 on threshold breach
uv run python evals/runners/run_evals.py --mode ciLatest eval results
๐ญ LangSmith Tracing
All LLM calls (UI + evals) are automatically traced to LangSmith when LANGCHAIN_TRACING_V2=true is set. No extra code required. View traces at smith.langchain.com.
๐ Deploying to HuggingFace Spaces
Step 1 โ Create a new Space
- Go to huggingface.co/new-space
- Fill in:
- Owner: your HuggingFace username or org
- Space name: e.g.
apextech-knowledge-base - License: choose one (e.g. MIT)
- SDK: select Docker
- Visibility: Private (this is an internal tool)
- Hardware: CPU Basic โ free tier (app peaks at ~470MB RAM โ )
- Click Create Space
Step 2 โ Add your OpenAI API key as a Secret
โ ๏ธ Do this before pushing code โ the build needs it to run the LLM.
- In your Space, go to Settings (top right)
- Scroll to Repository secrets
- Click New secret and add:
Step 3 โ Push your code to the Space
Run these commands from your project root:
# One-time setup: add the Space as a git remote
# Replace YOUR_USERNAME and SPACE_NAME with your actual values
git remote add space https://huggingface.co/spaces/YOUR_USERNAME/SPACE_NAME
# Push your master branch to the Space
git push space masterIf you get an authentication error, use a HuggingFace token: git remote set-url space https://YOUR_HF_TOKEN@huggingface.co/spaces/YOUR_USERNAME/SPACE_NAME Generate a token at huggingface.co/settings/tokens with write access.Step 4 โ Monitor the build
- Go to your Space page on HuggingFace
- Click the Build logs tab
- The build will:
- Install all Python dependencies (~3โ5 min)
- Download the HuggingFace embedding + reranker models (~2 min)
- Run
rag/ingest.pyto build the vector database (~1 min) - Start the Chainlit server on port 7860
- When the build is complete the Space shows Running (green)
- Click the app URL to open the assistant
Total first-build time: ~10โ15 minutes. Subsequent pushes are faster due to Docker layer caching.
Step 5 โ Updating the app
Every time you push to the space remote, HuggingFace rebuilds and redeploys automatically:
# Make your changes, commit, then:
git push space masterWhat the Dockerfile does at build time
Models and vector DB are baked into the image โ zero cold-start delay.
