Cody Context Selection
Learn about where does context come from and how Cody ensures it's good.
The quality of the context is critical, even with increasing context window sizes. Cody obtains context that is relevant to user input through the following methods:
Local Context
Cody initially looks at your local context by examining the currently open or recently accessed files within your code editor. By doing this, Cody aims to provide relevant information based on your recent work.
Keyword Search
Keyword Search is a traditional text search approach. It finds keywords matching your input and searches for those in the local code. It involves splitting content into terms and mapping terms to documents. At query time, terms from the query are matched to your documents. While powerful, this method can be used as a fallback solution when a codebase lacks embeddings.
Code Search
For more extensive searches, Cody utilizes Sourcegraph's Code Search. This powerful tool allows Cody to search beyond the local files and access non-local code repositories. Using an indexed trigram search, Cody can locate code snippets or relevant information from a broader range of sources.
Code Graph
Code Graph involves analyzing the structure of the code rather than treating it as plain text. Cody examines how different components of the codebase are interconnected and how they are used. This method is dependent on the code's structure and inheritance relationships. It can help Cody find context related to your input based on how code elements are linked and utilized.
Embeddings
Cody employs embeddings to find pieces of your codebase that are semantically related to your query. An LLM is used to pre-calculate the embeddings for your codebase so Cody can quickly find relevant chunks of code.