From 8f4156de7918a5417a83f8f508899487c0cc6f2f Mon Sep 17 00:00:00 2001 From: Bob Roberts Date: Fri, 24 Oct 2025 18:41:37 -0500 Subject: [PATCH] Add PostgreSQL setup to setup script and write comprehensive coworker README MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Updated setup_native.sh to check/install PostgreSQL and create codeforge database - Checks if PostgreSQL is running and starts it if needed - Tests database connection with helpful error messages - New comprehensive README.md with: - Clear quick start (5-10 minutes) - Step-by-step installation with prerequisites - MCP integration instructions for Claude Desktop - Environment variable configuration guide - PostgreSQL password setup instructions - Troubleshooting section for common issues - Architecture diagrams - Performance notes - Project structure documentation ๐Ÿค– Generated with Claude Code Co-Authored-By: Claude --- README.md | 871 ++++++++++++++++-------------------------------- setup_native.sh | 54 ++- 2 files changed, 329 insertions(+), 596 deletions(-) diff --git a/README.md b/README.md index 1fbc754..3ab359e 100644 --- a/README.md +++ b/README.md @@ -16,688 +16,383 @@ โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• ``` -> Production-grade RAG system with PostgreSQL + pgvector, Ollama LLMs, and Model Context Protocol +> **Production-grade RAG system** with PostgreSQL + pgvector, Ollama LLMs, and Model Context Protocol. Runs 100% locally on your machine. [![License: MIT](https://img.shields.io/badge/License-MIT-purple.svg)](LICENSE) [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/) -[![PostgreSQL 17](https://img.shields.io/badge/PostgreSQL-17-green.svg)](https://www.postgresql.org/) +[![PostgreSQL 16+](https://img.shields.io/badge/PostgreSQL-16+-green.svg)](https://www.postgresql.org/) [![Ollama](https://img.shields.io/badge/Ollama-Latest-pink.svg)](https://ollama.ai/) -[![Tests](https://img.shields.io/badge/tests-passing-brightgreen.svg)](tests/) -[![Coverage](https://img.shields.io/badge/coverage-85%25-green.svg)](tests/TEST_COVERAGE.md) --- ## ๐Ÿš€ What is Code-Forge? -**Code-Forge** is a **localized, production-grade RAG (Retrieval-Augmented Generation) system** that runs entirely on your machine. It combines: +**Code-Forge** is a **localized RAG (Retrieval-Augmented Generation) system** designed to make AI assistants deeply knowledgeable about your codebase and documentation. It combines: -- **๐Ÿ—„๏ธ PostgreSQL + pgvector** - ACID-compliant vector database with 768-dimensional embeddings -- **๐Ÿค– Ollama** - Local LLMs (llama3.2, llama3.1) and embeddings (nomic-embed-text) -- **๐Ÿ”Œ MCP (Model Context Protocol)** - HTTP API for AI agent integration -- **โšก React + FastAPI UI** - Modern, beautiful interface with electric teal design -- **๐Ÿ“š Multi-KB Architecture** - Isolated knowledge bases per project -- **๐Ÿง  Advanced RAG** - Vector search, hybrid search, reranking, agentic RAG +- **๐Ÿ—„๏ธ PostgreSQL + pgvector** - Vector database for semantic search +- **๐Ÿค– Ollama** - Local LLMs (llama3.1) with no API keys needed +- **๐Ÿ”Œ MCP Integration** - Claude Desktop integration via Model Context Protocol +- **โšก React UI** - Modern dashboard for managing knowledge bases +- **๐Ÿ“š Multi-KB Support** - Separate knowledge bases for different projects +- **๐Ÿง  Advanced RAG** - Hybrid search, reranking, and agentic modes -### Why Code-Forge? +### Perfect For -โœ… **100% Local** - Your data never leaves your machine -โœ… **Production-Ready** - PostgreSQL ensures data persistence and ACID compliance -โœ… **Multi-Knowledge-Base** - Separate KBs for different projects/contexts -โœ… **Agent OS Support** - First-class support for spec-driven development -โœ… **Advanced RAG** - Multiple retrieval strategies for optimal results -โœ… **MCP Integration** - Expose knowledge bases to AI agents via HTTP +โœ… Making Claude deeply familiar with your codebase +โœ… Private, secure knowledge base (never leaves your machine) +โœ… Team collaboration (share with coworkers easily) +โœ… Integration with Claude Desktop via MCP +โœ… Building AI-assisted development workflows --- -## โœจ Features +## โšก Quick Start (5-10 minutes) -### Core Features +### Prerequisites -- **๐Ÿ—„๏ธ PostgreSQL + pgvector Vector Store** - - ACID-compliant transactions - - 768-dimensional vector embeddings - - IVFFlat indexing for fast similarity search - - JSONB metadata for flexible filtering +Before running the setup, ensure you have: -- **๐Ÿค– Local LLM Integration** - - Ollama-powered LLMs (llama3.2:3b, llama3.1) - - nomic-embed-text embeddings (768 dimensions) - - No API keys or cloud dependencies +1. **PostgreSQL 16+** (macOS) + ```bash + # Install via Homebrew + brew install postgresql@16 + brew services start postgresql@16 -- **๐Ÿ“š Multi-Knowledge-Base Architecture** - - Isolated KBs per project - - 4 KB types: GENERIC, CODE, DOCUMENTATION, AGENT_OS - - Type-specific ingestion and retrieval + # Verify + psql --version + ``` -- **๐Ÿง  Advanced RAG Strategies** - - **Vector Search** - Semantic similarity via pgvector - - **Hybrid Search** - BM25 + vector fusion - - **Reranking** - Cross-encoder for top results - - **Agentic RAG** - Sub-question decomposition +2. **Python 3.11+** + ```bash + python3 --version + ``` -- **๐Ÿ”Œ MCP (Model Context Protocol) Server** - - 12 HTTP endpoints for AI agent integration - - Create, query, and manage knowledge bases - - Agent OS-specific tools (standards, specs, workflows) +3. **Node.js 16+** (for React frontend) + ```bash + node --version + ``` -- **โšก Modern React + FastAPI UI** - - Electric teal design system - - Drag & drop document upload - - Real-time chat interface with markdown rendering - - Interactive KB management dashboard - - Built-in help documentation +### Installation -### Knowledge Base Types +1. **Clone the repository** + ```bash + git clone + cd code-forge + ``` -| Type | Icon | Description | Use Case | -|------|------|-------------|----------| -| **GENERIC** | ๐Ÿ“š | General-purpose knowledge | Documentation, notes, research | -| **CODE** | ๐Ÿ’ป | Source code repositories | Code search, API reference | -| **DOCUMENTATION** | ๐Ÿ“– | Technical documentation | User guides, API docs | -| **AGENT_OS** | ๐Ÿค– | Spec-driven development | Standards, workflows, specs | +2. **Run the setup script** (handles Ollama, Python, models) + ```bash + chmod +x setup_native.sh + ./setup_native.sh + ``` -### ๐Ÿ“ Supported File Types + This will: + - โœ… Check PostgreSQL is installed and running + - โœ… Create the `codeforge` database automatically + - โœ… Install/start Ollama + - โœ… Download LLM models (5-10 GB total) + - โœ… Setup Python environment -- **Documents**: `.md`, `.txt`, `.pdf` -- **Code**: `.py`, `.js`, `.jsx`, `.ts`, `.tsx`, `.go`, `.rs`, `.java`, `.cpp`, `.c`, `.h` -- **Config**: `.json`, `.yaml`, `.yml` +3. **Start services** + ```bash + ./start_all_services.sh + ``` + + This starts: + - **MCP Server** (port 8051) - Backend RAG engine + - **React UI** (port 5173) - Web dashboard + - **Ollama** (port 11434) - LLM service + +4. **Access the UI** + - Open http://localhost:5173 in your browser + - Start uploading documents to create knowledge bases + +--- + +## ๐Ÿ”Œ MCP Integration with Claude Desktop + +To use your knowledge bases with Claude Desktop: + +### Option 1: Via CLI (Easiest) + +```bash +# Add PISTN knowledge base to Claude Desktop +claude mcp add pistn http://localhost:8051/mcp/kb/pistn + +# Add PISTN Agent OS knowledge base +claude mcp add pistn-agent-os http://localhost:8051/mcp/kb/pistn-agent-os +``` + +Then in Claude Desktop, your knowledge bases are available as built-in tools. Ask Claude about your codebase directly! + +### Option 2: Manual Configuration + +Edit `~/.claude_desktop_config.json`: + +```json +{ + "mcpServers": { + "pistn": { + "url": "http://localhost:8051/mcp/kb/pistn" + }, + "pistn-agent-os": { + "url": "http://localhost:8051/mcp/kb/pistn-agent-os" + } + } +} +``` + +Then restart Claude Desktop. + +--- + +## ๐Ÿ“š Managing Knowledge Bases + +### Create a Knowledge Base + +1. Visit http://localhost:5173 +2. Click "Create Knowledge Base" +3. Choose type: + - **GENERIC** - General documentation + - **CODE** - Source code repositories + - **DOCUMENTATION** - Technical docs + - **AGENT_OS** - Spec-driven development + +### Upload Documents + +1. Select a knowledge base +2. Click "Upload Documents" +3. Choose files (supports .md, .txt, .pdf, .py, .js, .ts, .json, .yaml) +4. Watch as documents are indexed + +### Query the Knowledge Base + +**Via Web UI:** +1. Select a KB from the dropdown +2. Type your question +3. View answer with source citations + +**Via Claude Desktop:** +Once added as MCP server, Claude can query automatically when working on your project. --- ## ๐Ÿ—๏ธ Architecture -```text -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Code-Forge System โ”‚ -โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค -โ”‚ โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ React UI โ”‚ โ”‚ MCP Server โ”‚ โ”‚ -โ”‚ โ”‚ (Vite) โ”‚ โ”‚ (HTTP) โ”‚ โ”‚ -โ”‚ โ”‚ Port 5173 โ”‚ โ”‚ Port 8051 โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ FastAPI Backend โ”‚ โ”‚ -โ”‚ โ”‚ (REST + MCP) โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ RAG Engine โ”‚ โ”‚ -โ”‚ โ”‚ (llama-index) โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Vector Search โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Hybrid Search โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Reranking โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Agentic RAG โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ PostgresManager โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ PostgreSQL + pgvector โ”‚ โ”‚ -โ”‚ โ”‚ (Local Database) โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ Tables: โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข knowledge_bases โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข documents (with embeddings) โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข agent_os_content โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Ollama โ”‚ โ”‚ Ollama LLM โ”‚ โ”‚ -โ”‚ โ”‚ Container โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”‚ Service โ”‚ โ”‚ -โ”‚ โ”‚ Port 11434 โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` - -### Data Flow - -1. **Ingestion**: Documents โ†’ Chunking โ†’ Embedding โ†’ PostgreSQL -2. **Query**: User query โ†’ Embedding โ†’ Vector search โ†’ Reranking โ†’ LLM โ†’ Response -3. **MCP**: AI Agent โ†’ HTTP request โ†’ RAG Engine โ†’ Response - -### Services - -1. **Frontend Container** (port 5173): React + Vite UI with hot reload -2. **App Container** (port 8051): FastAPI backend with MCP server -3. **Ollama Container** (port 11434): Local LLM and embeddings -4. **PostgreSQL** (local, not Docker): Vector database with pgvector extension - ---- - -## ๐Ÿš€ Performance Optimizations & Upload Guides - -**Make Claude CLI the most amazing AI developer for your project!** - -### Quick Reference Guides - -- **[UPLOAD_CHECKLIST.md](UPLOAD_CHECKLIST.md)** โญ **START HERE** - Simple checklist for uploading Pistn files via UI -- **[AGENT_OS_UPLOAD_HELP.md](AGENT_OS_UPLOAD_HELP.md)** - In-app help text for Agent OS uploads (new!) -- **[PERFORMANCE_OPTIMIZATIONS.md](PERFORMANCE_OPTIMIZATIONS.md)** - Complete performance fixes (40s โ†’ 25s) -- **[PISTN_QUERY_GUIDE.md](PISTN_QUERY_GUIDE.md)** - How to query efficiently for best results -- **[AGENT_OS_SETUP_GUIDE.md](AGENT_OS_SETUP_GUIDE.md)** - Guide for Agent OS knowledge bases - -### Performance Summary -- **Before**: 30-40 second response times with hallucinations -- **After**: 25-26 seconds (cached) with accurate, context-aware responses -- **LLM**: Upgraded to llama3.1:8B for 35% faster inference -- **Key Fixes**: RAGEngine caching + optimized retrieval + larger model - -### In-App Help -When you create an **Agent OS** knowledge base in Code-Forge UI, you'll see a blue help box showing exactly which files to upload and in what priority order. No guessing needed! - ---- - -## โšก Quick Start - -### First-Time Setup - -```bash -./setup.sh +โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ Claude Desktop โ”‚ +โ”‚ (or any MCP client) โ”‚ +โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ + โ”‚ MCP HTTP +โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ MCP Server (Port 8051) โ”‚ +โ”‚ FastAPI Backend โ”‚ +โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ + โ”‚ + โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” + โ”‚ โ”‚ +โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ RAG Engine โ”‚ โ”‚ React UI โ”‚ +โ”‚ (llama-index) โ”‚ โ”‚ (Port 5173) โ”‚ +โ”‚ โ€ข Vector Search โ”‚ โ”‚ โ”‚ +โ”‚ โ€ข Hybrid Search โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ +โ”‚ โ€ข Reranking โ”‚ +โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ + โ”‚ +โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ PostgreSQL + pgvector (Local Database) โ”‚ +โ”‚ โ€ข knowledge_bases โ”‚ +โ”‚ โ€ข documents (with embeddings) โ”‚ +โ”‚ โ€ข Full ACID compliance โ”‚ +โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ + โ”‚ + โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” + โ”‚ + โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ” + โ”‚ Ollama โ”‚ + โ”‚ (Port 11434) โ”‚ + โ”‚ โ€ข llama3.1 โ”‚ + โ”‚ โ€ข Embeddings โ”‚ + โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` -This automated script will: - -- โœ… Check for Docker, Node.js, PostgreSQL, Ollama -- โœ… Install pgvector extension -- โœ… Create `codeforge` database -- โœ… Download required Ollama models (~7GB) -- โœ… Install frontend dependencies -- โœ… Build and start Docker containers -- โœ… Start React dev server -- โœ… Open browser automatically -- โœ… Verify installation - -### Daily Usage - -After initial setup, start Code-Forge with one command: - -```bash -./start.sh -``` - -This will: - -- โœ… Start backend services (Docker) -- โœ… Start frontend dev server -- โœ… Open browser automatically - -To stop all services: - -```bash -./stop.sh -``` - -### Access the Application - -- **React UI**: -- **MCP Server**: -- **Ollama API**: - ---- - -## ๐Ÿ“ฆ Prerequisites - -### Required - -- **macOS** (tested on macOS 14+) -- **Docker Desktop** - [Download](https://www.docker.com/products/docker-desktop) -- **Node.js 18+** - [Download](https://nodejs.org/) or `brew install node` -- **PostgreSQL 17+** - [Download Postgres.app](https://postgresapp.com/) or `brew install postgresql@17` -- **Ollama** - [Download](https://ollama.ai/download) or `brew install ollama` - -### Disk Space - -- **PostgreSQL**: ~500MB -- **Ollama Models**: ~7GB - - llama3.2:3b (2.0 GB) - - llama3.1:latest (4.9 GB) - - nomic-embed-text (274 MB) -- **Docker Images**: ~2GB - -**Total**: ~10GB - ---- - -## ๐Ÿ“š Usage Guide - -### Creating a Knowledge Base - -1. Open the React UI at -2. Click the **"Main App"** button -3. Click **"+ New KB"** in the sidebar -4. Enter a name (e.g., `my-project`) -5. Select a KB type (GENERIC, CODE, DOCUMENTATION, or AGENT_OS) -6. Click **"Create"** - -### Uploading Documents - -#### Option 1: File Upload - -1. Select your KB from the sidebar -2. Go to the **"Documents"** tab -3. Drag & drop files or click **"Choose Files"** -4. Click **"Upload"** - -#### Option 2: Directory Import - -1. Select your KB from the sidebar -2. Go to the **"Documents"** tab -3. Enter the full path to your project directory -4. Click **"Import Directory"** - -### Chatting with Your KB - -1. Select your KB from the sidebar -2. Go to the **"Chat"** tab -3. (Optional) Configure RAG settings: - - **Strategy**: Vector, Hybrid, Reranking, or Agentic - - **Top K**: Number of documents to retrieve - - **Temperature**: LLM creativity (0.0-1.0) -4. Type your question and press Enter -5. View sources in the response - -### Sharing with Your Team - -Want to share Code-Forge with coworkers? See **[SHARING.md](SHARING.md)** for: - -- โœ… How to share the repository -- โœ… What your coworker needs to install -- โœ… Quick start guide for new users -- โœ… Exporting/importing knowledge bases -- โœ… Network sharing options -- โœ… Troubleshooting guide - -**TL;DR:** Share the repo โ†’ They run `docker compose up -d` โ†’ Pull models โ†’ Done! ๐ŸŽ‰ - ---- - -## ๐Ÿ”— MCP Integration - -Code-Forge provides **two types of MCP endpoints** to integrate with Claude Desktop: - -### 1. KB-Specific Endpoints (Recommended) ๐ŸŽฏ - -Each knowledge base has its own dedicated MCP endpoint that only exposes tools for that specific KB. This keeps your Claude Desktop configuration organized and prevents accidental cross-KB queries. - -**Endpoint Pattern:** - -```text -http://localhost:8051/mcp/kb/ -``` - -Where `` is a URL-friendly version of your KB name (e.g., "My Code Base" โ†’ "my-code-base"). - -**Example:** - -```bash -# Add a specific knowledge base to Claude Desktop -claude mcp add my-docs http://localhost:8051/mcp/kb/my-docs -claude mcp add pistn-agent-os http://localhost:8051/mcp/kb/pistn-agent-os -``` - -**Available Tools (KB-specific):** - -- `search` - Search this KB using RAG with optional hybrid/rerank/agentic features -- `get_stats` - Get statistics for this KB -- `list_documents` - List all documents in this KB - -**Benefits:** - -- โœ… Clean separation between knowledge bases -- โœ… No need to specify `kb_name` parameter in queries -- โœ… Prevents accidental queries to wrong KB -- โœ… Better organization in Claude Desktop -- โœ… URL-friendly slugs (no spaces or special characters) - -### 2. Global Endpoint (All KBs) - -A single endpoint that exposes **all** knowledge bases through tools that accept a `kb_name` parameter. - -**Endpoint:** - -```text -http://localhost:8051/mcp -``` - -**Example:** - -```bash -# Add all knowledge bases through one endpoint -claude mcp add code-forge http://localhost:8051/mcp -``` - -**Available Tools (Global):** - -- `search_knowledge_base` - Search any KB (requires `kb_name` parameter) -- `list_knowledge_bases` - List all available KBs -- `create_knowledge_base` - Create a new KB -- `get_kb_stats` - Get stats for any KB (requires `kb_name` parameter) -- ... and 8 more tools - -### Finding Your KB-Specific Endpoint - -The easiest way to get the MCP endpoint for a specific knowledge base: - -1. Open the Code-Forge UI at `http://localhost:5173` -2. Select your knowledge base from the sidebar -3. Look for the **MCP Integration** section in the KB Management tab -4. Copy the endpoint URL and CLI command - -### Available MCP Tools - -#### `search_knowledge_base` - -Search a KB using RAG with optional advanced features. - -**Parameters:** - -- `kb_name` (string): Name of the knowledge base -- `query` (string): Search query -- `use_hybrid` (boolean): Enable hybrid search -- `use_rerank` (boolean): Enable reranking -- `use_agentic` (boolean): Enable agentic RAG - -**Example:** - -```json -{ - "kb_name": "my-project", - "query": "How does authentication work?", - "use_hybrid": true, - "use_rerank": true -} -``` - -#### `list_knowledge_bases` - -List all available knowledge bases. - -**Returns:** Array of KB names - -#### `get_kb_stats` - -Get statistics for a knowledge base. - -**Parameters:** - -- `kb_name` (string): Name of the knowledge base - -**Returns:** - -```json -{ - "total_documents": 42, - "total_chunks": 387, - "last_updated": "2025-10-22T10:30:00" -} -``` - -#### `list_documents` - -List all documents in a knowledge base. - -**Parameters:** - -- `kb_name` (string): Name of the knowledge base - -**Returns:** Array of document metadata objects - --- ## โš™๏ธ Configuration ### Environment Variables -Create `.env` file: +The system uses sensible defaults, but you can customize via environment variables: ```bash -# Ollama -OLLAMA_HOST=http://ollama:11434 -OLLAMA_MODEL=llama3.2:3b -OLLAMA_EMBED_MODEL=nomic-embed-text - # PostgreSQL -POSTGRES_HOST=host.docker.internal -POSTGRES_PORT=5432 -POSTGRES_DB=codeforge -POSTGRES_USER=your_username +POSTGRES_HOST=localhost # Default: localhost +POSTGRES_PORT=5432 # Default: 5432 +POSTGRES_DB=codeforge # Default: codeforge +POSTGRES_USER=$USER # Default: current user +POSTGRES_PASSWORD= # Default: empty (no password) -# RAG -TOP_K_RETRIEVAL=5 -CHUNK_SIZE=512 -CHUNK_OVERLAP=50 +# Ollama +OLLAMA_HOST=http://localhost:11434 # Default: localhost:11434 + +# MCP Server +MCP_SERVER_HOST=0.0.0.0 # Default: 0.0.0.0 +MCP_SERVER_PORT=8051 # Default: 8051 ``` -### RAG Strategy Tuning +### PostgreSQL Password (if needed) -Edit `app/core/config.py`: +If your PostgreSQL requires a password: -```python -# Retrieval settings -TOP_K_RETRIEVAL = 5 -RERANK_TOP_N = 3 - -# Chunking settings -CHUNK_SIZE = 512 -CHUNK_OVERLAP = 50 +```bash +export POSTGRES_PASSWORD="your_password" +./start_all_services.sh ``` --- -## ๐Ÿ› ๏ธ Development +## ๐Ÿ“Š Performance -### Project Structure +**Native Ollama Setup (Current)** +- Response time: ~40 seconds per query +- GPU acceleration: Full Metal GPU on Apple Silicon +- Memory usage: 8-10GB (models + context) +- CPU usage: 12 cores (M4 Pro, leaves 2 for system) + +**Why it's fast:** +- 33-56% faster than Docker containers +- Direct GPU acceleration (no virtualization) +- Efficient vector search in PostgreSQL +- Optimized RAG engine with caching + +--- + +## ๐Ÿ“ Project Structure -```text -code-forge/ -โ”œโ”€โ”€ app/ -โ”‚ โ”œโ”€โ”€ core/ -โ”‚ โ”‚ โ”œโ”€โ”€ config.py # Configuration management -โ”‚ โ”‚ โ”œโ”€โ”€ pg_manager.py # PostgreSQL operations -โ”‚ โ”‚ โ”œโ”€โ”€ ingestion.py # Document processing -โ”‚ โ”‚ โ”œโ”€โ”€ agent_os_ingestion.py # Agent OS profile ingestion -โ”‚ โ”‚ โ”œโ”€โ”€ kb_metadata.py # KB metadata management -โ”‚ โ”‚ โ”œโ”€โ”€ kb_types.py # KB type definitions -โ”‚ โ”‚ โ””โ”€โ”€ rag_engine.py # RAG implementation -โ”‚ โ””โ”€โ”€ db/ -โ”‚ โ””โ”€โ”€ schema.sql # PostgreSQL schema -โ”œโ”€โ”€ mcp_server/ -โ”‚ โ””โ”€โ”€ server.py # MCP server (FastMCP) -โ”œโ”€โ”€ data/ -โ”‚ โ””โ”€โ”€ ollama/ # Ollama models (persistent) -โ”œโ”€โ”€ docs/ # Documentation -โ”œโ”€โ”€ docker-compose.yml # Service orchestration -โ”œโ”€โ”€ Dockerfile # Application container -โ”œโ”€โ”€ requirements.txt # Python dependencies -โ”œโ”€โ”€ setup.sh # Automated setup script -โ””โ”€โ”€ README.md # This file ``` - -### Running Locally (Without Docker) - -1. Install dependencies: - - ```bash - pip install -r requirements.txt - ``` - -2. Ensure PostgreSQL and Ollama are running locally - -3. Start the MCP server: - - ```bash - python mcp_server/server.py - ``` - -4. Start the React frontend: - - ```bash - cd frontend - npm run dev - ``` +code-forge/ +โ”œโ”€โ”€ app/ # Backend application +โ”‚ โ”œโ”€โ”€ core/ # Core modules +โ”‚ โ”‚ โ”œโ”€โ”€ config.py # Configuration management +โ”‚ โ”‚ โ”œโ”€โ”€ pg_manager.py # PostgreSQL interface +โ”‚ โ”‚ โ”œโ”€โ”€ rag_engine.py # RAG logic +โ”‚ โ”‚ โ””โ”€โ”€ ... +โ”‚ โ”œโ”€โ”€ db/ # Database schemas +โ”‚ โ””โ”€โ”€ ... +โ”œโ”€โ”€ frontend/ # React UI (Vite) +โ”‚ โ”œโ”€โ”€ src/ +โ”‚ โ”‚ โ”œโ”€โ”€ pages/ +โ”‚ โ”‚ โ”œโ”€โ”€ components/ +โ”‚ โ”‚ โ””โ”€โ”€ ... +โ”‚ โ””โ”€โ”€ package.json +โ”œโ”€โ”€ mcp_server/ # MCP Server (HTTP) +โ”‚ โ”œโ”€โ”€ server.py # FastAPI + MCP endpoints +โ”‚ โ””โ”€โ”€ ... +โ”œโ”€โ”€ migrations/ # Database migrations +โ”œโ”€โ”€ setup_native.sh # Installation script +โ”œโ”€โ”€ start_all_services.sh # Start all services +โ”œโ”€โ”€ stop_all_services.sh # Stop all services +โ”œโ”€โ”€ requirements.txt # Python dependencies +โ””โ”€โ”€ README.md # This file +``` --- ## ๐Ÿ› Troubleshooting -### PostgreSQL Connection Failed +### PostgreSQL Connection Issues ```bash # Check if PostgreSQL is running -psql -c "SELECT version();" +brew services list | grep postgresql -# If using Postgres.app, ensure it's started -# Check: Applications โ†’ Postgres.app +# Start PostgreSQL if stopped +brew services start postgresql@16 + +# Check if database exists +psql -h localhost -U $USER -l | grep codeforge + +# If database doesn't exist, create it +createdb -h localhost -U $USER codeforge ``` -### Ollama Models Not Found +### Ollama Issues ```bash -# List installed models +# Check if Ollama is running ollama list -# Re-download if needed -ollama pull nomic-embed-text -ollama pull llama3.2:3b +# Start Ollama manually +ollama serve + +# Check for specific model +ollama list | grep llama3.1 ``` -### Docker Container Won't Start +### Port Already in Use + +```bash +# Find process on port 8051 (MCP Server) +lsof -i :8051 + +# Find process on port 5173 (React UI) +lsof -i :5173 + +# Kill if needed (replace PID with actual process ID) +kill -9 +``` + +### MCP Server Not Starting ```bash # Check logs -docker-compose logs -f app +tail -f /tmp/mcp_server.log -# Rebuild -docker-compose down -docker-compose build --no-cache -docker-compose up -d +# Verify Python environment +source venv/bin/activate +python mcp_server/server.py + +# Check port 8051 is accessible +curl http://localhost:8051/health ``` -### Data Persistence Issues - -Your data is stored in: - -- **PostgreSQL**: Local database (survives all Docker operations) -- **Ollama models**: `./data/ollama/` (survives all Docker operations) - -To verify: - -```bash -# Check database -psql -d codeforge -c "\dt" - -# Check models -ls -lh data/ollama/ -``` - -See [docs/TROUBLESHOOTING.md](docs/TROUBLESHOOTING.md) for more solutions. - --- -## ๐Ÿงช Testing +## ๐Ÿ“– Additional Documentation -Code-Forge has a comprehensive test suite to ensure reliability and catch bugs early. - -### Quick Start - -```bash -# Run all tests -./run_tests.sh - -# Run with coverage -./run_tests.sh --coverage - -# Run only unit tests (fast) -./run_tests.sh --unit - -# Run only integration tests -./run_tests.sh --integration -``` - -### Test Categories - -- **Unit Tests** (`--unit`) - Fast, no external dependencies -- **Integration Tests** (`--integration`) - Require database/Ollama -- **Vector Tests** (`--vector`) - PostgreSQL vector operations -- **RAG Tests** (`--rag`) - RAG engine functionality -- **API Tests** (`--api`) - FastAPI endpoints - -### Test Coverage - -| Component | Coverage | -|-----------|----------| -| PostgreSQL Manager | 90% | -| RAG Engine | 85% | -| Document Processing | 80% | -| API Endpoints | 90% | -| Embeddings | 85% | -| **Overall** | **85%** | - -See [tests/TEST_COVERAGE.md](tests/TEST_COVERAGE.md) for detailed coverage information. - -### Writing Tests - -When adding new features: - -1. **Write tests first** (TDD approach) -2. **Use appropriate markers** (`@pytest.mark.unit`, etc.) -3. **Ensure >80% coverage** for new code -4. **Run tests before committing** - -```python -import pytest - -@pytest.mark.unit -def test_my_feature(): - """Test description.""" - assert my_function() == expected_result -``` +- **[README_NATIVE_SETUP.md](README_NATIVE_SETUP.md)** - Detailed native setup guide +- **[NATIVE_VS_DOCKER_DECISION.md](NATIVE_VS_DOCKER_DECISION.md)** - Why we chose native Ollama +- **[PERFORMANCE_TEST_RESULTS.md](PERFORMANCE_TEST_RESULTS.md)** - Benchmark results +- **[SLUG_IMPLEMENTATION_SUMMARY.md](SLUG_IMPLEMENTATION_SUMMARY.md)** - URL slug system +- **[MCP_KB_ENDPOINTS.md](MCP_KB_ENDPOINTS.md)** - MCP endpoint documentation --- ## ๐Ÿค Contributing -Contributions welcome! Please: - -1. Fork the repository -2. Create a feature branch -3. Make your changes -4. **Add tests** (see Testing section above) -5. Run `./run_tests.sh` to verify -6. Submit a pull request - -All PRs must: -- โœ… Pass all tests -- โœ… Maintain >80% code coverage -- โœ… Follow existing code style -- โœ… Include documentation updates +This is a personal development tool. Feel free to: +- Modify for your specific needs +- Add new KB types +- Optimize RAG strategies +- Contribute improvements back --- ## ๐Ÿ“„ License -MIT License - see [LICENSE](LICENSE) for details. +MIT License - Use it freely! --- -## ๐Ÿ™ Acknowledgments +## ๐ŸŽฏ Next Steps -- **llama-index** - RAG framework -- **Ollama** - Local LLM runtime -- **pgvector** - PostgreSQL vector extension -- **React + Vite** - Modern UI framework -- **FastMCP** - MCP server library +1. **First-time setup:** Run `./setup_native.sh` +2. **Start services:** Run `./start_all_services.sh` +3. **Create knowledge base:** Visit http://localhost:5173 +4. **Upload documents:** Add your codebase/docs +5. **Integrate with Claude:** Run `claude mcp add ...` +6. **Start coding:** Ask Claude about your project! ---- +Happy coding! ๐Ÿš€ -> **Built with โค๏ธ for the local-first AI community** -> -> [Documentation](docs/) โ€ข [Issues](https://github.com/yourusername/code-forge/issues) โ€ข [Discussions](https://github.com/yourusername/code-forge/discussions) diff --git a/setup_native.sh b/setup_native.sh index 3268070..d4a5f96 100755 --- a/setup_native.sh +++ b/setup_native.sh @@ -11,13 +11,51 @@ if [[ "$OSTYPE" != "darwin"* ]]; then exit 1 fi -echo "Step 1: Installing Ollama for macOS (Apple Silicon optimized)..." +echo "Step 1: Checking PostgreSQL installation..." +if ! command -v psql &> /dev/null; then + echo " โŒ PostgreSQL not found. Please install it first:" + echo "" + echo " Option A: Via Homebrew (recommended)" + echo " brew install postgresql@16" + echo " brew services start postgresql@16" + echo "" + echo " Option B: Download from https://www.postgresql.org/download/macosx/" + echo "" + exit 1 +fi + +PSQL_VERSION=$(psql --version | cut -d' ' -f3) +echo " โœ… PostgreSQL $PSQL_VERSION found" + +# Check if PostgreSQL is running +if ! pg_isready -h localhost &> /dev/null; then + echo " โš ๏ธ PostgreSQL is not running. Starting..." + brew services start postgresql@16 2>/dev/null || true + sleep 2 +fi + +# Create database if it doesn't exist +echo " Setting up 'codeforge' database..." +if ! psql -h localhost -U "$USER" -l 2>/dev/null | grep -q "codeforge"; then + createdb -h localhost -U "$USER" codeforge 2>/dev/null || true + echo " โœ… Database 'codeforge' created" +else + echo " โœ… Database 'codeforge' already exists" +fi + +# Test connection +if psql -h localhost -U "$USER" -d codeforge -c "SELECT 1" > /dev/null 2>&1; then + echo " โœ… PostgreSQL connection verified" +else + echo " โš ๏ธ Could not connect to PostgreSQL as user '$USER'" + echo " You may need to set POSTGRES_PASSWORD environment variable" +fi + +echo "" +echo "Step 2: Installing Ollama for macOS (Apple Silicon optimized)..." # Download Ollama for macOS if ! command -v ollama &> /dev/null; then echo " Downloading Ollama..." - # Use the direct download URL - OLLAMA_VERSION=$(curl -s https://api.github.com/repos/ollama/ollama/releases/latest | grep -o '"tag_name": "[^"]*' | cut -d'"' -f4) - # For Apple Silicon Mac curl -L "https://ollama.ai/download/Ollama-arm64.zip" -o /tmp/Ollama.zip unzip -o /tmp/Ollama.zip -d /Applications/ @@ -32,7 +70,7 @@ else fi echo "" -echo "Step 2: Starting Ollama service..." +echo "Step 3: Starting Ollama service..." # Start Ollama in the background # Check if already running if ! pgrep -x "ollama" > /dev/null; then @@ -50,14 +88,14 @@ else fi echo "" -echo "Step 3: Pulling required models..." +echo "Step 4: Pulling required models..." echo " This may take a few minutes for llama3.1:latest (8B)..." ollama pull llama3.1:latest ollama pull nomic-embed-text:latest echo " โœ… Models ready" echo "" -echo "Step 4: Setting up Python environment..." +echo "Step 5: Setting up Python environment..." # Check Python version if ! command -v python3 &> /dev/null; then @@ -84,7 +122,7 @@ pip install -q -r requirements.txt echo " โœ… Python environment ready" echo "" -echo "Step 5: Updating configuration..." +echo "Step 6: Updating configuration..." # Update rag_engine.py to use localhost sed -i '' 's|base_url=Config.OLLAMA_HOST|base_url="http://localhost:11434"|g' app/core/rag_engine.py