Skip to content

Commit

Permalink
add context and chat docs (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
FuzzyReason authored May 6, 2024
1 parent c4efe14 commit 06b0a5e
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 2 deletions.
3 changes: 2 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ export default defineConfig({
label: 'Features',
items: [
{ label: 'AI Chat', link: '/features/ai-chat/' },
{ label: 'Code Completion', link: '/features/code-completion/' },
{ label: 'AI Toolbox', link: '/features/ai-toolbox/' },
{ label: 'Code Completion', link: '/features/code-completion/' },
{ label: 'Context', link: '/features/context/' },
]
},
],
Expand Down
Binary file added src/assets/ast_vecdb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/refact_settings_rag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/starcoder2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/thenpler.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions src/content/docs/features/ai-chat.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,53 @@ description: A reference page for AI Chat.
---

You can ask questions about your code in the integrated AI chat, and it can provide you with answers about your code or generate new code for you based on the context of your current file.

## @-commands

This section outlines various commands that can be used in the AI chat. Below you can find information about functionality and usage of each command.

### `@workspace`

- **Description**: Searches within VecDB for any specified query. This command allows you to search for any query within your repository/workspace.
- **Usage**:
- Single-line Query: Append the query directly after the command, e.g., `@workspace Something definition`.
- Multi-line Query: Type the command followed by pressing `Enter`. Subsequent lines entered will be considered part of the query, allowing for multi-line entries such as code snippets.

### `@file`

- **Description**: Attaches a file to the chat.
- **Usage**:
- To attach a whole file, use the command followed by the file name, e.g., `@file example.ext`.
- To specify a particular section of a file, include the line numbers, e.g., `@file large_file.ext:42` or for a range, `@file large_file.ext:42-56`.

### `@definition`

- **Description**: Retrieves the definition of a symbol.
- **Usage**: Type `@definition` followed by the symbol name, e.g., `@definition MyClass`.

### `@references`

- **Description**: Returns references for a symbol, including usage examples.
- **Usage**: Type `@references` followed by the symbol name, e.g., `@references MyClass`.

### `@symbols-at`

- **Description**: Searches for and adds symbols near a specified line in a file to the chat context.
- **Usage**: Specify both the file and the line number, e.g., `@symbols-at some_file.ext:42`.

## Chat Initialization Options

Upon starting a new chat, several options are available that mimic the above commands:

- `Search workspace`: Equivalent to using `@workspace`. It uses the entered query to perform a search.
- `Attach current_file.ext`: Similar to the `@file` command. It attaches the file at the current cursor position (CURSOR_LINE), useful for dealing with large files.
- `Lookup symbols`: Corresponds to the `@symbols-at` command. It extracts symbols around the cursor position and searches them in the AST index.
- `Selected N lines`: Adds the currently selected lines as a snippet for analysis or modification. This is similar to embedding code within backticks ``` in the chat.

## Enabling commands

To use @-commands in the AI chat, you need to enable specific settings:
- `@workspace` - enable the `Enable embedded vecdb for search` checkbox under the `Refactai: Vecdb` section.
- `@definition`, `@file`, `@references`, `@symbols-at` - enable the `Enable syntax parsing` checkbox under the `Refactai: Ast` section.

Read more in the [Enabling RAG Documentation](https://docs.refact.ai/features/context/).
53 changes: 53 additions & 0 deletions src/content/docs/features/context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: Context
description: A reference page about the context.
---

Context refers to the surrounding information that Refact.ai uses to provide a better quality of generated code. This can include:
- **Code Syntax**: By analyzing the current state of the code, Refact.ai can provide syntactically correct code completions.
- **Developer's Intent**: Interpreting comments, variable names, and function signatures, Refact.ai can provide code suggestions that are more relevant to the developer's intent.
- **Repo-level awareness**: By analyzing the repository's codebase, Refact.ai can provide code suggestions that are more relevant to the existing codebase.

## RAG
Refact.ai uses RAG (Retrieval-Augmented Generation) to fill the
context with the information that is needed to provide a better quality of generated code.

### Enabling RAG

In order to enable RAG, you need to follow the instructions depending on the version of the Refact.ai you are using.

### Cloud Version

1. In the settings of the plugin (can be accessed by pressing the cogwheel icon in the sidebar), under the `Refactai: Code Completion Model` section, specify the `starcoder2/3b` model.
![Refact Settings](../../../assets/refact_settings_rag.png)
2. To enable RAG for **code completion**, you need to enable the `Enable syntax parsing` checkbox under the `Refactai: Ast` section.
3. To enable RAG for the **AI chat**, you need to enable the `Enable embedded vecdb for search` checkbox under the `Refactai: Vecdb` section. Read more in the [AI Chat Documentation](https://docs.refact.ai/features/ai-chat/) about available features.

![RAG Settings](../../../assets/ast_vecdb.png)

:::note
RAG is more useful for the context size **more than 2048 tokens**, which is available for **Pro users**.

Be aware that RAG indexing is a **high resource-consuming process**, so you will experience increased memory consumption of your **GPU, RAM, and CPU**.
:::
### Refact Enterprise

1. In the Web UI of your Refact.ai instance, navigate to the `Model Hosting` page. press the `Add Model` button to switch the model, locate and select one of the `starcoder2/` models.
![Starcoder2 model](../../../assets/starcoder2.png)
:::note
You can use different models from the `starcoder2` family. But be aware that with Stacoder2 models, the results will be more accurate and the code completion will be more accurate.
:::
2. To enable RAG for **code completion**, you need to enable the `Enable syntax parsing` checkbox under the `Refactai: Ast` section.
3. To enable RAG for the **AI chat**, you need to enable the `Enable embedded vecdb for search` checkbox under the `Refactai: Vecdb` section. Read more in the [AI Chat Documentation](https://docs.refact.ai/features/ai-chat/) about available features.
![RAG Settings](../../../assets/ast_vecdb.png)
4. If Vecdb checkbox is enabled in your VS Code settings, you need to select the `thenlper/gte-base` model in your Refact.ai instance.
In the Web UI of your Refact.ai instance, navigate to the `Model Hosting` page. Press the `Add Model` button, locate and select the `thenlper/gte-base` model.
![thenlper model](../../../assets/thenpler.png)

:::note
Make sure that you have enough memory available on your GPU for the model to be loaded and served.

Altrnitavely you can use unoccupied GPU to avoid the memory issue and interruption of the code generation.

As an aditional option, you can switch from vLLM model to a regular model.
:::
2 changes: 1 addition & 1 deletion src/content/docs/guides/deployment/aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Replace `"/path/to/your/refact_id_rsa.pem"` with the actual path to your downloa

## Deploy Refact

Once connected via SSH, continue to the [Refact Enterprise](https://docs.refact.ai/guides/enterprise/) page to learn how to use Refact for teams.
Once connected via SSH, continue to the [Refact Enterprise](https://docs.refact.ai/guides/version-specific/enterprise/) page to learn how to use Refact for teams.

## Known issues

Expand Down

0 comments on commit 06b0a5e

Please sign in to comment.