feat: add vector-space code indexing and semantic search support

Resolved 💬 5 comments Opened Apr 24, 2025 by nerdielol Closed Sep 3, 2025

🚀 Feature Request

📌 Problem

The Codex CLI currently provides powerful completions via the Completions API, but it lacks semantic code search. Developers must fall back to grep or file-name heuristics, which:
• Miss semantically similar code when names differ
• Are brittle across large or polyglot codebases
• Don’t leverage project-specific patterns or style

💡 Proposed Solution

Introduce first-class support for vector embeddings and approximate-nearest-neighbor search:

  1. New CLI Commands

Build/update a vector index over your code

codex index --vector [--db faiss|pinecone|qdrant] [--src PATH]

Perform semantic search by intent

codex search --vector "<natural language query>" [--top K] [--filter EXT|PATH|TAG]

  1. Indexing Behavior

• Walk the source tree (default .)
• Split files into logical chunks (functions, classes)
• Call the OpenAI Embeddings API (e.g. ada-code-002)
• Bulk-load vectors + metadata (file paths, byte offsets) into the chosen vector store

  1. Search Behavior

• Embed the user’s query
• Run an ANN lookup (cosine similarity or L2)
• Return the top-K snippets with file paths, line ranges, and relevance scores

  1. Configuration

• New settings in ~/.codex/config.json for API key, embedding model, vector-db connection, and default chunk size
• Sensible defaults: in-process FAISS for small repos

🔧 Alternatives Considered
• External scripts using the OpenAI client + vector-db libraries
• Keyword-based grepping via codex grep or shell pipelines
• Manual code navigation in IDEs without semantic awareness

📝 Additional Context & Use Cases
• Improved Completions: Retrieve project-specific helpers before calling the Completions API, reducing prompt noise.
• “Related Code” Sidebar: IDE plugins (VS Code, IntelliJ, Neovim) can call codex search --vector under the hood to power a live “Related Code” panel.
• Duplication Detection: Find near-duplicate functions or patterns for refactoring.
• RAG Workflows: Enable retrieval-augmented generation using your own code as context.

I’m happy to contribute a PR that scaffolds the new CLI commands and demonstrates basic FAISS integration. Please let me know if there’s interest in adding this feature!

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗