From 4a06d5b3e717d221de248bb240167fa0a4942c62 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 10 Jan 2024 23:24:01 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20update=20codebase=20embeddings?= =?UTF-8?q?=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/docs/walkthroughs/codebase-embeddings.md | 99 ++++++++++++++----- 1 file changed, 74 insertions(+), 25 deletions(-) diff --git a/docs/docs/walkthroughs/codebase-embeddings.md b/docs/docs/walkthroughs/codebase-embeddings.md index 69b6b0d35..a3a83e803 100644 --- a/docs/docs/walkthroughs/codebase-embeddings.md +++ b/docs/docs/walkthroughs/codebase-embeddings.md @@ -4,61 +4,110 @@ description: Talk to your codebase keywords: [talk, embeddings, codebase, experimental] --- -# Codebase Retrieval +# Codebase retrieval -Continue indexes your codebase so that when you input a message using Command+Enter, it can automatically pull in the most relevant context from throughout your workspace. This is done via a combination of embeddings-based retrieval and keyword search. By default, all embeddings are calculated locally with `all-MiniLM-L6-v2` and stored locally in `~/.continue/index`. +Continue indexes your codebase so that it can later automatically pull in the most relevant context from throughout your workspace. This is done via a combination of embeddings-based retrieval and keyword search. By default, all embeddings are calculated locally with `all-MiniLM-L6-v2` and stored locally in `~/.continue/index`. -The codebase retrieval feature allows the following customization options by editing `config.json` as follows: +## How to use codebase retrieval + +Currently, the codebase retrieval feature is available as the "codebase" context provider. You can use it by typing `@codebase` in the input box, and then asking a question. The contents of the input box will be compared with the embeddings from the rest of the codebase to determine relevant files. + +There are a few options that let you configure the behavior of the codebase context provider. These can be set in `config.json`: ```json title="~/.continue/config.json" { - "retrievalSettings": { - "nRetrieve": 100, - ... + "contextProviders": [ + { + "name": "codebase", + "params": { + "nRetrieve": 25, + "nFinal": 5, + "useReranking": true + } } + ] } ``` ### `nRetrieve` -Number of results to initially retrieve from vector database (default: 50) +Number of results to initially retrieve from vector database (default: 25) ### `nFinal` -Final number of results to use after re-ranking (default: 10) +Final number of results to use after re-ranking (default: 5) ### `useReranking` -Whether to use re-ranking, which will allow initial selection of `nRetrieve` results, then will use an LLM to select the top `nFinal` results (default: True) +Whether to use re-ranking, which will allow initial selection of `nRetrieve` results, then will use an LLM to select the top `nFinal` results (default: true) -### `rerankGroupSize` +## Embeddings providers -Number of results to group together when re-ranking. Each group will be processed in parallel. (default: 5) +We also support other methods of generating embeddings, which can be configured with the `"embeddingsProvider"` property in `config.json`. We currently have built-in support for the following providers: -### `ignoreFiles` +### Transformers.js -Files to ignore when indexing the codebase. You can use glob patterns, such as `**/*.py`. This is useful for directories that contain generated code, or other directories that are not relevant to the codebase. (default: []) +[Transformers.js](https://huggingface.co/docs/transformers.js/index) is a JavaScript port of the popular [Transformers](https://huggingface.co/transformers/) library. It allows embeddings to be calculated locally in the browser (or in this case inside of the sidebar of your IDE). The model used is `all-MiniLM-L6-v2`, which is shipped alongside the Continue extension and generates embeddings of size 384. -### `openaiApiKey` +```json title="~/.continue/config.json" +{ + "embeddingsProvider": { + "name": "transformers.js" + } +} +``` -OpenAI API key. If set, Continue will calculate embeddings by calling OpenAI's `ada-002` embeddings API. (default: None) +### Ollama -### Azure OpenAI +[Ollama](https://ollama.ai) is the easiest way to get up and running with open-source language models. It provides an entirely local REST API for working with LLMs, including generating embeddings. The embeddings generated are slightly larger, with a size of 4096 for `codellama:7b`. -These settings allow you to connect to an Azure-hosted OpenAI API. All must be filled out in order to use Azure OpenAI for embeddings, as well as the `openaiApiKey`. +```json title="~/.continue/config.json" +{ + "embeddingsProvider": { + "name": "ollama", + "model": "codellama:7b", + "apiBase": "http://localhost:11434" // optional, defaults to http://localhost:11434 + } +} +``` -#### `apiBase` +### OpenAI -OpenAI API base URL (default: None) +```json title="~/.continue/config.json" +{ + "embeddingsProvider": { + "name": "openai", + "model": "text-embedding-ada-002", // optional, defaults to "text-embedding-ada-002" + "apiBase": "" // optional, defaults to OpenAI's API + } +} +``` -#### `apiType` +### Writing a custom `EmbeddingsProvider` -OpenAI API type (default: None) +If you have your own API capable of generating embeddings, Continue makes it easy to write a custom `EmbeddingsProvider`. All you have to do is write a function that converts strings to arrays of numbers, and add this to your config in `config.ts`. Here's an example: -#### `apiVersion` +```ts title="~/.continue/config.ts" +export function modifyConfig(config: Config): Config { + config.embeddingsProvider = { + embed: (chunks: string[]) => { + return Promise.all( + chunks.map(async (chunk) => { + const response = await fetch("https://example.com/embeddings", { + method: "POST", + body: JSON.stringify({ text: chunk }), + }); + const data = await response.json(); + return data.embedding; + }) + ); + }, + }; -OpenAI API version (default: None) + return config; +} +``` -#### `organizationId` +## Customizing which files are indexed -OpenAI organization ID (default: None) +Continue respects `.gitignore` files in order to determine which files should not be indexed. If you'd like to exclude additional files, you can add them to a `.continueignore` file, which follows the exact same rules as `.gitignore`.