codex icon indicating copy to clipboard operation
codex copied to clipboard

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

Open nerdielol opened this issue 1 year ago • 5 comments

🚀 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 "" [--top K] [--filter EXT|PATH|TAG]

2.	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
3.	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
4.	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!

nerdielol avatar Apr 24 '25 02:04 nerdielol

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

Orad avatar Aug 27 '25 21:08 Orad

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!

dedrisian-oai avatar Sep 03 '25 00:09 dedrisian-oai

@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?

solomatov avatar Sep 17 '25 17:09 solomatov

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

familyfriendlymikey avatar Sep 25 '25 13:09 familyfriendlymikey

Definitely needed for large code bases

styler-ai avatar Oct 11 '25 14:10 styler-ai