Polars FastEmbed
A Polars plugin for embedding DataFrames
Installation
uv pip install polars-fastembed[cpu]
Change the [cpu] package extras according to your system:
- for use with GPU:
[cuda] - for backcompatibility with older CPUs:
[rtcompat]
Features
- Embed from a DataFrame by specifying the source column(s)
- Re-order/filter rows by semantic similarity to a query
- Efficiently reuse loaded models via a global registry (no repeated model loads)
- Auto-detects GPU availability; uses CUDA if installed, otherwise CPU
Demo
See demo.py
import polars as pl
from polars_fastembed import register_model, CUDA_AVAILABLE
# Create a sample DataFrame
df = pl.DataFrame(
{
"id": [1, 2, 3],
"text": [
"Hello world",
"Deep Learning is amazing",
"Polars and FastEmbed are well integrated",
],
}
)
model_id = "Xenova/bge-small-en-v1.5"
# 1) Register a model
# By default, uses GPU if available, otherwise CPU
register_model(model_id)
# Or explicitly control providers:
# register_model(model_id, cuda=False) # Force CPU only
# register_model(model_id, cuda=True) # Require GPU (error if unavailable)
# 2) Embed your text
df_emb = df.fastembed.embed(
columns="text",
model_name=model_id,
output_column="embedding",
)
# Inspect embeddings
print(f"CUDA available: {CUDA_AVAILABLE}")
print(df_emb)
# 3) Perform retrieval
result = df_emb.fastembed.retrieve(
query="Tell me about deep learning",
model_name=model_id,
embedding_column="embedding",
k=3,
)
print(result)
shape: (3, 3)
┌─────┬─────────────────────────────────┬─────────────────────────────────┐
│ id ┆ text ┆ embedding │
│ --- ┆ --- ┆ --- │
│ i64 ┆ str ┆ array[f32, 384] │
╞═════╪═════════════════════════════════╪═════════════════════════════════╡
│ 1 ┆ Hello world ┆ [0.015196, -0.022571, … 0.0260… │
│ 2 ┆ Deep Learning is amazing ┆ [-0.016128, -0.018325, … -0.06… │
│ 3 ┆ Polars and FastEmbed are well … ┆ [-0.086584, 0.026477, … 0.0399… │
└─────┴─────────────────────────────────┴─────────────────────────────────┘
shape: (3, 4)
┌─────┬─────────────────────────────────┬─────────────────────────────────┬────────────┐
│ id ┆ text ┆ embedding ┆ similarity │
│ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ str ┆ array[f32, 384] ┆ f64 │
╞═════╪═════════════════════════════════╪═════════════════════════════════╪════════════╡
│ 2 ┆ Deep Learning is amazing ┆ [-0.016128, -0.018325, … -0.06… ┆ 0.825373 │
│ 3 ┆ Polars and FastEmbed are well … ┆ [-0.086584, 0.026477, … 0.0399… ┆ 0.543264 │
│ 1 ┆ Hello world ┆ [0.015196, -0.022571, … 0.0260… ┆ 0.52316 │
└─────┴─────────────────────────────────┴─────────────────────────────────┴────────────┘
Note:
- This will download a 133 MB model to your working directory under
.fastembed_cache - In the original version this was a 384-dimensional array of f64 and here it is a list of f32. This will become an array as well in future versions (watch this space).
Contributing
Feel free to open issues or submit pull requests for improvements or bug fixes.
License
MIT License
Metadata
Release files for polars-fastembed 0.1.17
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| polars_fastembed-0.1.17.tar.gz | 123.7 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| polars_fastembed-0.1.17-cp38-abi3-win_amd64.whl | CPython 3.8 | abi3 | Windows x86-64 | Details |
| polars_fastembed-0.1.17-cp38-abi3-manylinux_2_28_i686.whl | CPython 3.8 | abi3 | Linux glibc 2.28+ x86-32 | Details |
| polars_fastembed-0.1.17-cp38-abi3-macosx_11_0_arm64.whl | CPython 3.8 | abi3 | macOS 11.0+ ARM64 | Details |
| polars_fastembed-0.1.17-cp38-abi3-macosx_10_12_x86_64.whl | CPython 3.8 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 34.2 MB
Release files / polars_fastembed-0.1.17.tar.gz
| Download URL | polars_fastembed-0.1.17.tar.gz |
|---|---|
| Size | 123.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
10f03933afbf532cb569d3c0c867e37dbae0652c471d6ee5d5a5f806e420811d
|
|
BLAKE2b-256 checksum How to use checksums |
64125fad278f9fcdba6e9355e3a3fcc3ccd3f32d330a2f42d86309aa826c8ef4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.10.2
|
Release files / polars_fastembed-0.1.17-cp38-abi3-win_amd64.whl
| Download URL | polars_fastembed-0.1.17-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 8.2 MB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
52f15dc0798e7686980942e503eea080ec167d8f09f3065446950f7dd664a1f6
|
|
BLAKE2b-256 checksum How to use checksums |
183d6ac141b6e980b2bc3b0033e7644916952739f7c12b73df196f53643b98d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.10.2
|
Release files / polars_fastembed-0.1.17-cp38-abi3-manylinux_2_28_i686.whl
| Download URL | polars_fastembed-0.1.17-cp38-abi3-manylinux_2_28_i686.whl |
|---|---|
| Size | 15.8 MB |
| Tags | CPython 3.8 Linux glibc 2.28+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
6b29a04e8789bb15eed15f113806e399ee786c70e390667ac30e32c2de8f5811
|
|
BLAKE2b-256 checksum How to use checksums |
8604526d03afa1832d952f2a8c8517b273263b2ed7f9eb6175780712a2fc00c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.10.2
|
Release files / polars_fastembed-0.1.17-cp38-abi3-macosx_11_0_arm64.whl
| Download URL | polars_fastembed-0.1.17-cp38-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.7 MB |
| Tags | CPython 3.8 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
93b6d93fafe0a808d7a1c6fa7598582f5b4a082e27a927c2ab1304b76814dc83
|
|
BLAKE2b-256 checksum How to use checksums |
cc70dfe8ece61e998c10c275f72fdbb166c6a5f2f36241c228ca51b840f2c64b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.10.2
|
Release files / polars_fastembed-0.1.17-cp38-abi3-macosx_10_12_x86_64.whl
| Download URL | polars_fastembed-0.1.17-cp38-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 5.4 MB |
| Tags | CPython 3.8 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
24c5cdae5c83adc260c32b72df437de02809caa0ba05fa411f49aac297318cc0
|
|
BLAKE2b-256 checksum How to use checksums |
8b0c6e98b6fa11f9f3e3e500cbab0f5c25117bba9229ea78e029a389229ca667
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.10.2
|