# Knowledge search (/features/ai/knowledge-search)

## Reranking \[#reranking]

New in v2026.4.7

✅ After the initial document retrieval, VBT can now rerank results using a dedicated reranking model
to surface the most relevant documents. Five providers are supported out of the box: Cohere, Jina, Voyage,
Hugging Face cross-encoders (local), and any LLM via completions-based scoring.

=== "Example 1: Search with reranking"
    ```python title="Rerank search results using Cohere"
    >>> env["COHERE_API_KEY"] = "<YOUR_COHERE_API_KEY>"

    >>> vbt.search(  # (1)
    ...     "How to rebalance weekly?",
    ...     rerank=True,  # (2)
    ...     reranker="cohere",  # (3)
    ...     rerank_limit=20,  # (4)
    ... )
    ```

    1.  Works the same way with `vbt.chat()`, `vbt.quick_chat()`, and `vbt.interact()`.
    2.  Enable reranking after the initial retrieval pass.
    3.  Choose a reranker. Available options: `"cohere"`, `"jina"`, `"voyage"`, `"hf_cross_encoder"`, `"completions"`.
    4.  Only the top 20 documents from the initial ranking are sent to the reranker.

=== "Example 2: Chat with local reranking"
    ```python title="Rerank using a local cross-encoder model"
    >>> env["OPENAI_API_KEY"] = "<YOUR_OPENAI_API_KEY>"

    >>> vbt.chat(  # (1)
    ...     "How to use stop losses with from_signals?",
    ...     rank_kwargs=dict(
    ...         rerank=True,
    ...         reranker="hf_cross_encoder",  # (2)
    ...     ),
    ...     formatter="html",
    ... )
    ```

    1.  Pass reranking parameters through `rank_kwargs` when calling `vbt.chat()`.
    2.  Use a Hugging Face cross-encoder model for fully local, offline reranking.

!!! info "Cookbook"
    Don't use OpenAI? Explore more configurations in the knowledge section of the [Cookbook](/cookbook/).

## Source refactorer \[#source-refactorer]

New in v2025.5.11

✅ Use the source refactorer to automatically enhance any Python code, whether it is a full package,
Python object, or raw string. If the source is larger than expected, it intelligently splits it
into clean AST-based chunks, refactors each using an LLM, and merges them back into polished code.
You can choose to return the result, update the source in place, or copy it to your clipboard.
For full transparency, you can also preview the diff directly in your browser ✏️

```python title="Complete a signal function"
>>> env["GITHUB_TOKEN"] = "<YOUR_GITHUB_TOKEN>"
>>> env["OPENAI_API_KEY"] = "<YOUR_OPENAI_API_KEY>"

>>> source = """
... @njit
... def signal_func_nb(ctx, entries, exits):
...     is_entry = vbt.pf_nb.select_nb(ctx, entries)
...     is_exit = vbt.pf_nb.select_nb(ctx, exits)
...
...     # TODO: Enter only if no other asset is active
...
...     return is_entry, is_exit, False, False
... """  # (1)

>>> new_source = vbt.refactor_source(
...     source,
...     attach_knowledge=True,  # (2)
...     model="gpt-5-mini",
...     reasoning=dict(effort="high"),
...     show_diff=True,  # (3)
... )
>>> print(new_source)

@njit
def signal_func_nb(ctx, entries, exits):
    is_entry = vbt.pf_nb.select_nb(ctx, entries)
    is_exit = vbt.pf_nb.select_nb(ctx, exits)
    for col in range(ctx.from_col, ctx.to_col):
        if col != ctx.col and ctx.last_position[col] != 0:
            is_entry = False
            break
    return is_entry, is_exit, False, False
```

1.  Use **TODO** or **FIXME** comments to provide custom instructions.
2.  Attach relevant knowledge from the website and Discord.
3.  Show the produced changes in a browser.

![](/assets/images/features/intelligence/source_refiner.light.png#only-light)
![](/assets/images/features/intelligence/source_refiner.dark.png#only-dark)

## Quick search & chat \[#quick-search--chat]

New in v2025.5.11

✅ In addition to embeddings, which require prior generation, VBT now supports
[BM25](https://en.wikipedia.org/wiki/Okapi_BM25) for fast, fully offline lexical search.
This is perfect for quickly finding something specific.

```python title="Search VBT knowledge for a warning"
>>> env["GITHUB_TOKEN"] = "<YOUR_GITHUB_TOKEN>"

>>> vbt.quick_search("UserWarning: Symbols have mismatching index")
```

=== "Page 1"
    ![](/assets/images/features/intelligence/quick_search1.light.png#only-light)
    ![](/assets/images/features/intelligence/quick_search1.dark.png#only-dark)

=== "Page 2"
    ![](/assets/images/features/intelligence/quick_search2.light.png#only-light)
    ![](/assets/images/features/intelligence/quick_search2.dark.png#only-dark)

=== "Page 3"
    ![](/assets/images/features/intelligence/quick_search3.light.png#only-light)
    ![](/assets/images/features/intelligence/quick_search3.dark.png#only-dark)

## SearchVBT \[#searchvbt]

New in v2025.3.1

✅ Want to find specific information using natural language on the website or Discord?
VBT provides a powerful smart search feature called SearchVBT. Enter your query and it will
generate an HTML page with well-structured search results. Behind the scenes, SearchVBT uses a
[RAG](https://en.wikipedia.org/wiki/Retrieval-augmented_generation) pipeline to embed, rank, and
retrieve only the most relevant documents from VBT, ensuring precise and efficient search results.

```python title="Search VBT knowledge for a warning"
>>> env["GITHUB_TOKEN"] = "<YOUR_GITHUB_TOKEN>"
>>> env["OPENAI_API_KEY"] = "<YOUR_API_KEY>"

>>> vbt.search("How to run indicator expressions?")
```

=== "Page 1"
    ![](/assets/images/features/intelligence/searchvbt1.light.png#only-light)
    ![](/assets/images/features/intelligence/searchvbt1.dark.png#only-dark)

=== "Page 2"
    ![](/assets/images/features/intelligence/searchvbt2.light.png#only-light)
    ![](/assets/images/features/intelligence/searchvbt2.dark.png#only-dark)

=== "Page 3"
    ![](/assets/images/features/intelligence/searchvbt3.light.png#only-light)
    ![](/assets/images/features/intelligence/searchvbt3.dark.png#only-dark)

## Knowledge assets \[#knowledge-assets]

New in v2024.11.12

✅ Each [release](https://github.com/polakowo/vectorbt.pro/releases) now includes valuable
knowledge assets—JSON files containing private website content and the complete "vectorbt.pro" Discord
history. These assets can be used with LLMs and services like Cursor. In addition, VBT offers
a palette of classes for working with these assets, providing functions such as
converting to Markdown and HTML files, browsing the website offline, performing targeted searches,
interacting with LLMs, and much more!

```python title="Gather all pages and messages that define signal_func_nb"
>>> env["GITHUB_TOKEN"] = "<YOUR_GITHUB_TOKEN>"

>>> pages_asset = vbt.PagesAsset.pull()  # (1)
>>> messages_asset = vbt.MessagesAsset.pull()
>>> vbt_asset = pages_asset + messages_asset
>>> code = vbt_asset.find_code("def signal_func_nb", return_type="item")
>>> code.print_sample(seed=42)  # (2)
```

1.  The first pull will download the assets, while subsequent pulls will use the cached versions.
2.  Print a random code snippet.

````yaml
link: https://discord.com/channels/x/918630948248125512/1251081573147742298
block: https://discord.com/channels/x/918630948248125512/1251081573147742298
thread: https://discord.com/channels/x/918630948248125512/1250844139952541837
reference: https://discord.com/channels/x/918630948248125512/1250844139952541837
replies:
- https://discord.com/channels/x/918630948248125512/1251083513336299610
channel: support
timestamp: '2024-06-14 07:51:31'
author: '@polakowo'
content: Something like this
mentions:
- '@fei'
attachments:
- file_name: Screenshot_2024-06-13_at_20.29.45-B4517.png
  content: |-
    Here's the text extracted from the image:

    ```python
    @njit
    def signal_func_nb(ctx, entries, exits, wait):
        is_entry = vbt.pf_nb.select_nb(ctx, entries)
        if is_entry:
            return True, False, False, False
        is_exit = vbt.pf_nb.select_nb(ctx, exits)
        if is_exit:
            if vbt.pf_nb.in_position_nb(ctx):
                last_order = vbt.pf_nb.get_last_order_nb(ctx)
                if ctx.index[ctx.i] - ctx.index[last_order["idx"]] >= wait:
                    return False, True, False, False
        return False, False, False, False

    pf = vbt.PF.from_random_signals(
        "BTC-USD",
        n=100,
        seed=42,
        signal_func_nb=signal_func_nb,
        signal_args=(
            vbt.Rep("entries"),
            vbt.Rep("exits"),
            vbt.dt.to_ns(vbt.timedelta("1000 days"))
        )
    )
    ```
reactions: 0
````
