|
18 | 18 | * [Vectorising Your Code](#vectorising-your-code) |
19 | 19 | * [File Specs](#file-specs) |
20 | 20 | * [Making a Query](#making-a-query) |
| 21 | + * [Query Rewriting](#query-rewriting) |
21 | 22 | * [Listing All Collections](#listing-all-collections) |
22 | 23 | * [Removing a Collection](#removing-a-collection) |
23 | 24 | * [Checking Project Setup](#checking-project-setup) |
@@ -356,7 +357,13 @@ The JSON configuration file may hold the following values: |
356 | 357 | command line flag. You can also set this to `_auto`, which uses |
357 | 358 | [charset-normalizer](https://charset-normalizer.readthedocs.io/en/latest/index.html) |
358 | 359 | to automatically detect the encoding, but this is not very accurate, |
359 | | - especially on small files. |
| 360 | + especially on small files; |
| 361 | +- `rewriter`: string, the type of rewriter to use. Currently the only supported |
| 362 | + value is `OpenAIRewriter`, which uses a openai-compatible LLM provider as the |
| 363 | + rewriter; |
| 364 | +- `rewriter_params`: dictionary, the options to be used for the construction of |
| 365 | + the rewriter. The options are documented in [the source |
| 366 | + code](../src/vectorcode/rewriter/). |
360 | 367 |
|
361 | 368 | See |
362 | 369 | [the wiki](https://github.com/Davidyz/VectorCode/wiki/Default-Configuration#default-cli-configuration) |
@@ -461,6 +468,47 @@ the number of retrieved chunks when you use `--include chunk`. For the sake of |
461 | 468 | completeness, the first and last lines of a chunk will be completed to include |
462 | 469 | the whole lines if the chunker broke the text from mid-line. |
463 | 470 |
|
| 471 | +#### Query Rewriting |
| 472 | +
|
| 473 | +When your query messages are noisy (for example, containing a lot of symbols |
| 474 | +that are not relevant to the RAG tasks), the retrieval results may be |
| 475 | +compromised. To address this, you can try to use |
| 476 | +[query rewriting](https://docs.llamaindex.ai/en/stable/examples/query_transformations/query_transform_cookbook/#query-rewriting). |
| 477 | +The VectorCode implementation of query rewriting uses an LLM to rewrite your |
| 478 | +search query so that it contains a curated list of keywords and (hopefully) will |
| 479 | +improve your search results. To do this, you'd need to [configure your rewriter](#configuring-vectorcode) |
| 480 | +and pass the `--rewrite` flag to your query command. For example: |
| 481 | +```json5 |
| 482 | +// .vectorcode/config.json |
| 483 | +// `OpenAIRewriter` works for any openai-compatible LLM API service that works |
| 484 | +// provides structured_output. |
| 485 | +{ |
| 486 | + "rewriter": "OpenAIRewriter", |
| 487 | + "rewriter_params": { |
| 488 | + "client_kwargs": { |
| 489 | + // see openai.Client |
| 490 | + // https://github.com/openai/openai-python/blob/67997a4ec1ebcdf8e740afb0d0b2e37897657bde/src/openai/_client.py#L80 |
| 491 | + "base_url": "https://api.siliconflow.cn/v1", |
| 492 | + "api_key": "$SILICONFLOW_API_KEY" |
| 493 | + }, |
| 494 | + "completion_kwargs": { |
| 495 | + // see openai.Client.beta.chat.completions.parse |
| 496 | + // https://github.com/openai/openai-python/blob/main/helpers.md#structured-outputs-parsing-helpers |
| 497 | + "model": "Qwen/Qwen2.5-7B-Instruct", |
| 498 | + "temperature": 0 |
| 499 | + } |
| 500 | + } |
| 501 | +} |
| 502 | +``` |
| 503 | + |
| 504 | +And when making a query, if you pass the `--rewrite` flag, VectorCode will send |
| 505 | +your query message to the LLM and get a list of strings, which it will use as |
| 506 | +the query for the search: |
| 507 | + |
| 508 | +```bash |
| 509 | +vectorcode query "reranker implementation" "class" "struct" "transformers" --rewrite |
| 510 | +``` |
| 511 | + |
464 | 512 | ### Listing All Collections |
465 | 513 |
|
466 | 514 | You can use `vectorcode ls` command to list all collections in your ChromaDB. |
|
0 commit comments