Skip to content

Vashanth/Personal-knowledge-base-RAG

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Local PKB + Chat Memory (Offline, Postgres + pgvector + Ollama)

This project provides:

  • FastAPI backend
  • PostgreSQL + pgvector memory store
  • LangChain-based chunking + embeddings for RAG
  • Ollama local generation with llama3.1:8b
  • Optional Claude cloud generation via dropdown selection
  • Minimal React frontend

1. Install dependencies

Backend

cd /Users/vashanth/Desktop/Repos/vash/pkb/backend
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
cp .env.example .env

Frontend

cd /Users/vashanth/Desktop/Repos/vash/pkb/frontend
npm install

2. Start PostgreSQL and create database

Using Homebrew services:

/opt/homebrew/bin/brew install postgresql@17 pgvector
/opt/homebrew/bin/brew services stop postgresql@16 || true
/opt/homebrew/bin/brew services start postgresql@17

# Creates the DB using your local macOS username role (typical on Homebrew Postgres).
createdb pkb

3. Enable pgvector and schema

Apply schema:

psql -d pkb -f /Users/vashanth/Desktop/Repos/vash/pkb/backend/schema.sql

If psql -d pkb fails with a role error, set DATABASE_URL in /Users/vashanth/Desktop/Repos/vash/pkb/backend/.env to:

  • DATABASE_URL=postgresql://$USER@localhost:5432/pkb

Optional: never persist names/emails/phones

Set REDACT_PII=1 in /Users/vashanth/Desktop/Repos/vash/pkb/backend/.env to redact common PII patterns before embedding/storing.

4. Start Ollama and pull models

ollama serve
ollama pull llama3.1:8b
ollama pull nomic-embed-text

4b. Optional Claude cloud model

Set these in /Users/vashanth/Desktop/Repos/vash/pkb/backend/.env:

  • CLAUDE_API_KEY=your_key_here
  • CLAUDE_MODEL=claude-3-5-sonnet-latest
  • CLAUDE_BASE_URL=https://api.anthropic.com
  • ALLOW_CLAUDE_WITHOUT_OLLAMA=1
  • EMBEDDING_FALLBACK_PROVIDER=simple

When Claude is selected in the frontend dropdown, backend generation is sent to Anthropic API. If Ollama embeddings are unavailable, Claude mode can still run semantic RAG using a deterministic local simple embedding fallback. If Claude returns 404, your model id is usually not available for your account/version; set CLAUDE_MODEL to one available in your Anthropic console.

5. Run backend

cd /Users/vashanth/Desktop/Repos/vash/pkb/backend
source .venv/bin/activate
uvicorn app.main:app --reload --port 8000

6. Ingest notes (.txt/.md)

cd /Users/vashanth/Desktop/Repos/vash/pkb/backend
source .venv/bin/activate
python ingest_notes.py /absolute/path/to/notes_or_files

7. Run frontend

cd /Users/vashanth/Desktop/Repos/vash/pkb/frontend
npm run dev

Open http://127.0.0.1:5173

API

POST /chat

Request:

{
  "question": "What did I say about my onboarding plan?",
  "session_id": "optional-existing-session-id",
  "top_k": 8,
  "model_provider": "llama"
}

Response includes:

  • answer
  • context (exact injected context block)
  • retrieved items
  • session_id
  • model_provider

Retrieval behavior

  • Retrieval combines:
    • recent conversation items from the same session_id
    • semantic vector matches from memory_items
  • This avoids failures where repeated short questions (for example, "what's my name") dominate nearest-neighbor results.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors