|
| 1 | +# h-codex |
| 2 | + |
| 3 | +A semantic code search tool for intelligent, cross-repo context retrieval. |
| 4 | + |
| 5 | +## ✨ Features |
| 6 | + |
| 7 | +- **AST-Based Chunking**: Intelligent code parsing using Abstract Syntax Trees for optimal chunk boundaries |
| 8 | +- **Embedding & Semantic Search**: Using OpenAI's `text-embedding-3-small` model (support for `voyage-code-3` planned) |
| 9 | +- **Vector Database**: PostgreSQL with pgvector extension for efficient similarity search |
| 10 | +- **Multi-Language Support**: TypeScript, JavaScript, and extensible for other languages |
| 11 | +- **MCP Integration**: Seamlessly connects with AI coding assistants through Model Context Protocol |
| 12 | + |
| 13 | +## 🚀 Getting started |
| 14 | + |
| 15 | +h-codex can be integrated with AI assistants through the Model Context Protocol. |
| 16 | + |
| 17 | +### Example with Claude Desktop |
| 18 | + |
| 19 | +Edit your `claude_mcp_settings.json` file: |
| 20 | + |
| 21 | +```json |
| 22 | +{ |
| 23 | + "mcpServers": { |
| 24 | + "h-codex": { |
| 25 | + "command": "npx", |
| 26 | + "args": ["@h-codex/mcp"], |
| 27 | + "env": { |
| 28 | + "OPENAI_API_KEY": "your_openai_api_key_here", |
| 29 | + "DB_CONNECTION_STRING": "postgresql://postgres:password@localhost:5432/h-codex" |
| 30 | + } |
| 31 | + } |
| 32 | + } |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +## 🛠️ Development |
| 37 | + |
| 38 | +### Prerequisites |
| 39 | + |
| 40 | +- [Node.js](https://nodejs.org/) (v18+) |
| 41 | +- [pnpm](https://pnpm.io/) - Package manager |
| 42 | +- [Docker](https://www.docker.com/) - For running PostgreSQL with pgvector |
| 43 | +- OpenAI API key for embeddings |
| 44 | + |
| 45 | +### Getting Started |
| 46 | + |
| 47 | +1. **Clone the repository** |
| 48 | + |
| 49 | + ```bash |
| 50 | + git clone https://github.com/hpbyte/h-codex.git |
| 51 | + cd h-codex |
| 52 | + ``` |
| 53 | + |
| 54 | +2. **Set up environment variables** |
| 55 | + |
| 56 | + ```bash |
| 57 | + cp packages/core/.env.example packages/core/.env |
| 58 | + ``` |
| 59 | + |
| 60 | + Edit the `.env` file with your OpenAI API key and other configuration options. |
| 61 | + |
| 62 | +3. **Install dependencies** |
| 63 | + |
| 64 | + ```bash |
| 65 | + pnpm install |
| 66 | + ``` |
| 67 | + |
| 68 | +4. **Start PostgreSQL database** |
| 69 | + |
| 70 | + ```bash |
| 71 | + cd dev && docker compose up -d |
| 72 | + ``` |
| 73 | + |
| 74 | +5. **Set up the database** |
| 75 | + |
| 76 | + ```bash |
| 77 | + pnpm run db:migrate |
| 78 | + ``` |
| 79 | + |
| 80 | +6. **Start development server** |
| 81 | + |
| 82 | + ```bash |
| 83 | + pnpm dev |
| 84 | + ``` |
| 85 | + |
| 86 | +## 🔧 Configuration Options |
| 87 | + |
| 88 | +| Environment Variable | Description | Default | |
| 89 | +| ---------------------- | -------------------------------- | ------------------------------------------------------- | |
| 90 | +| `OPENAI_API_KEY` | OpenAI API key for embeddings | Required | |
| 91 | +| `EMBEDDING_MODEL` | OpenAI model for embeddings | `text-embedding-3-small` | |
| 92 | +| `CHUNK_SIZE` | Maximum chunk size in characters | `1000` | |
| 93 | +| `SEARCH_RESULTS_LIMIT` | Max search results returned | `10` | |
| 94 | +| `SIMILARITY_THRESHOLD` | Minimum similarity for results | `0.5` | |
| 95 | +| `DB_CONNECTION_STRING` | PostgreSQL connection string | `postgresql://postgres:password@localhost:5432/h-codex` | |
| 96 | + |
| 97 | +## 🏗️ Architecture |
| 98 | + |
| 99 | +```mermaid |
| 100 | +graph TD |
| 101 | + subgraph "Core Package" |
| 102 | + subgraph "Ingestion Pipeline" |
| 103 | + Explorer["Explorer<br/>(file discovery)"] |
| 104 | + Chunker["Chunker<br/>(AST parsing & chunking)"] |
| 105 | + Embedder["Embedder<br/>(semantic embeddings)"] |
| 106 | + Indexer["Indexer<br/>(orchestration)"] |
| 107 | +
|
| 108 | + Explorer --> Chunker |
| 109 | + Chunker --> Embedder |
| 110 | + Embedder --> Indexer |
| 111 | + end |
| 112 | +
|
| 113 | + subgraph "Storage Layer" |
| 114 | + Repository["Repository"] |
| 115 | + end |
| 116 | +
|
| 117 | + Indexer --> Repository |
| 118 | + Repository --> Database[(PostgreSQL Vector Database)] |
| 119 | + end |
| 120 | +
|
| 121 | + subgraph "MCP Package" |
| 122 | + MCPServer["MCP Server"] |
| 123 | + CodeIndexTool["Code Index Tool"] |
| 124 | + CodeSearchTool["Code Search Tool"] |
| 125 | +
|
| 126 | + MCPServer --> CodeIndexTool |
| 127 | + MCPServer --> CodeSearchTool |
| 128 | + end |
| 129 | +
|
| 130 | + CodeIndexTool --> Indexer |
| 131 | + CodeSearchTool --> Repository |
| 132 | +``` |
| 133 | + |
| 134 | +## 🗺️ Roadmap |
| 135 | + |
| 136 | +- Support for additional embedding providers (Voyage AI) |
| 137 | +- Enhanced language support with more tree-sitter parsers |
| 138 | + |
| 139 | +## 📄 License |
| 140 | + |
| 141 | +This project is licensed under the MIT License |
0 commit comments