Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 134 additions & 4 deletions docs-website/reference/integrations-api/fastembed.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ slug: "/fastembed-embedders"
### FastembedDocumentEmbedder

FastembedDocumentEmbedder computes Document embeddings using Fastembed embedding models.

The embedding of each Document is stored in the `embedding` field of the Document.

Usage example:
Expand Down Expand Up @@ -445,12 +446,141 @@ Embeds text using the Fastembed model.

- <code>TypeError</code> – If the input is not a string.

## haystack_integrations.components.rankers.fastembed.late_interaction_ranker

### FastembedLateInteractionRanker

Ranks Documents based on their similarity to the query using ColBERT models via Fastembed.

Uses late interaction (MaxSim) scoring to compute token-level similarity between
query and document embeddings, then ranks documents accordingly.

See https://qdrant.github.io/fastembed/examples/Supported_Models/ for supported models.

Usage example:

```python
from haystack import Document
from haystack_integrations.components.rankers.fastembed import FastembedLateInteractionRanker

ranker = FastembedLateInteractionRanker(model_name="colbert-ir/colbertv2.0", top_k=2)

docs = [Document(content="Paris"), Document(content="Berlin")]
query = "What is the capital of germany?"
output = ranker.run(query=query, documents=docs)
print(output["documents"][0].content)

# Berlin
```

#### __init__

```python
__init__(
model_name: str = "colbert-ir/colbertv2.0",
top_k: int = 10,
cache_dir: str | None = None,
threads: int | None = None,
batch_size: int = 64,
parallel: int | None = None,
local_files_only: bool = False,
meta_fields_to_embed: list[str] | None = None,
meta_data_separator: str = "\n",
score_threshold: float | None = None,
) -> None
```

Creates an instance of the 'FastembedLateInteractionRanker'.

**Parameters:**

- **model_name** (<code>str</code>) – Fastembed ColBERT model name. Check the list of supported models in the
[Fastembed documentation](https://qdrant.github.io/fastembed/examples/Supported_Models/).
- **top_k** (<code>int</code>) – The maximum number of documents to return.
- **cache_dir** (<code>str | None</code>) – The path to the cache directory.
Can be set using the `FASTEMBED_CACHE_PATH` env variable.
Defaults to `fastembed_cache` in the system's temp directory.
- **threads** (<code>int | None</code>) – The number of threads single onnxruntime session can use. Defaults to None.
- **batch_size** (<code>int</code>) – Number of strings to encode at once.
- **parallel** (<code>int | None</code>) – If > 1, data-parallel encoding will be used, recommended for offline encoding of large datasets.
If 0, use all available cores.
If None, don't use data-parallel processing, use default onnxruntime threading instead.
- **local_files_only** (<code>bool</code>) – If `True`, only use the model files in the `cache_dir`.
- **meta_fields_to_embed** (<code>list\[str\] | None</code>) – List of meta fields that should be concatenated
with the document content for reranking.
- **meta_data_separator** (<code>str</code>) – Separator used to concatenate the meta fields
to the Document content.
- **score_threshold** (<code>float | None</code>) – If provided, only documents with a score above the threshold are returned.
Note that ColBERT scores are unnormalized sums and typically range from 3 to 25.

#### to_dict

```python
to_dict() -> dict[str, Any]
```

Serializes the component to a dictionary.

**Returns:**

- <code>dict\[str, Any\]</code> – Dictionary with serialized data.

#### from_dict

```python
from_dict(data: dict[str, Any]) -> FastembedLateInteractionRanker
```

Deserializes the component from a dictionary.

**Parameters:**

- **data** (<code>dict\[str, Any\]</code>) – The dictionary to deserialize from.

**Returns:**

- <code>FastembedLateInteractionRanker</code> – The deserialized component.

#### warm_up

```python
warm_up() -> None
```

Initializes the component.

#### run

```python
run(
query: str, documents: list[Document], top_k: int | None = None
) -> dict[str, list[Document]]
```

Returns a list of documents ranked by their similarity to the given query using ColBERT MaxSim scoring.

**Parameters:**

- **query** (<code>str</code>) – The input query to compare the documents to.
- **documents** (<code>list\[Document\]</code>) – A list of documents to be ranked.
- **top_k** (<code>int | None</code>) – The maximum number of documents to return.

**Returns:**

- <code>dict\[str, list\[Document\]\]</code> – A dictionary with the following keys:
- `documents`: A list of documents closest to the query, sorted from most similar to least similar.

**Raises:**

- <code>ValueError</code> – If `top_k` is not > 0.

## haystack_integrations.components.rankers.fastembed.ranker

### FastembedRanker

Ranks Documents based on their similarity to the query using
[Fastembed models](https://qdrant.github.io/fastembed/examples/Supported_Models/).
Ranks Documents based on their similarity to the query using Fastembed models.

See https://qdrant.github.io/fastembed/examples/Supported_Models/ for supported models.

Documents are indexed from most to least semantically relevant to the query.

Expand Down Expand Up @@ -483,7 +613,7 @@ __init__(
local_files_only: bool = False,
meta_fields_to_embed: list[str] | None = None,
meta_data_separator: str = "\n",
)
) -> None
```

Creates an instance of the 'FastembedRanker'.
Expand Down Expand Up @@ -537,7 +667,7 @@ Deserializes the component from a dictionary.
#### warm_up

```python
warm_up()
warm_up() -> None
```

Initializes the component.
Expand Down
Loading
Loading