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

Resolved 💬 5 comments Opened Apr 24, 2025 by nerdielol Closed Sep 3, 2025
💡 Likely answer: A maintainer (dedrisian-oai, contributor) responded on this thread — see the highlighted reply below.

🚀 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 ↗

5 Comments

Orad · 1 year ago

I'd love to see this implemented. for now here is an alternative: https://github.com/qdrant/mcp-server-qdrant

dedrisian-oai contributor · 11 months ago

Hey! Thank you for the feature suggestion. This is not currently on our roadmap, and in order to keep our open list of issues maintainable, we'll close this for now. Appreciate the input!

solomatov · 11 months ago

@dedrisian-oai Is it possible to share your thinking behind it? I.e. why vectors search wouldn't help much or why is it hard to implement?

familyfriendlymikey · 11 months ago

I'm also curious. This is probably the only thing keeping me going back to Cursor.

styler-ai · 10 months ago

Definitely needed for large code bases