Skip to main content

A Polars plugin for text embeddings in DataFrames

Project description

Polars FastEmbed

uv pdm-managed PyPI Supported Python versions License pre-commit.ci status

A Polars plugin for embedding DataFrames

Installation

uv pip install polars-fastembed

Or for backcompatibility with older CPUs:

uv pip install polars-fastembed[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)

Demo

See demo.py

import polars as pl
from polars_fastembed import register_model

# 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
#    Optionally specify GPU: providers=["CUDAExecutionProvider"]
#    Or omit it for CPU usage
register_model(model_id, providers=["CPUExecutionProvider"])

# 2) Embed your text
df_emb = df.fastembed.embed(
    columns="text",
    model_name=model_id,
    output_column="embedding",
)

# Inspect embeddings
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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polars_fastembed-0.1.13.tar.gz (116.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

polars_fastembed-0.1.13-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl (7.3 MB view details)

Uploaded PyPymanylinux: glibc 2.28+ ARM64

polars_fastembed-0.1.13-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl (7.3 MB view details)

Uploaded PyPymanylinux: glibc 2.28+ ARM64

polars_fastembed-0.1.13-cp38-abi3-win_amd64.whl (5.3 MB view details)

Uploaded CPython 3.8+Windows x86-64

polars_fastembed-0.1.13-cp38-abi3-manylinux_2_28_i686.whl (7.5 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.28+ i686

polars_fastembed-0.1.13-cp38-abi3-manylinux_2_28_aarch64.whl (7.3 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.28+ ARM64

polars_fastembed-0.1.13-cp38-abi3-macosx_11_0_arm64.whl (4.7 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

polars_fastembed-0.1.13-cp38-abi3-macosx_10_12_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file polars_fastembed-0.1.13.tar.gz.

File metadata

  • Download URL: polars_fastembed-0.1.13.tar.gz
  • Upload date:
  • Size: 116.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for polars_fastembed-0.1.13.tar.gz
Algorithm Hash digest
SHA256 b83bcaf8490be794b53d9e6c66e7bbca90429495a26a15568ab5d84691fe2884
MD5 a155788b6fa34958aab07afb7e3daae7
BLAKE2b-256 510b14960574471e05feed4c680998ff7e3f2239f296c2e6a268ddec4da1135f

See more details on using hashes here.

File details

Details for the file polars_fastembed-0.1.13-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for polars_fastembed-0.1.13-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d293373dd4b15100e600896fdbf334b9cca0ca4c8f3890fad1aa2655624c0072
MD5 589f1ced96ec35a52a209947bfe5c75c
BLAKE2b-256 a15eee18c8283d458c57259248aeccfa1f4293472a0ab47dd27455b0b025775e

See more details on using hashes here.

File details

Details for the file polars_fastembed-0.1.13-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for polars_fastembed-0.1.13-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 19ee1b4f18de48e2835ac2d858beaf47f6f6db564538bc2fc497399345dd0491
MD5 15226d0741c02bfd4ea790798ad6817b
BLAKE2b-256 c9b46042d2f61dbc133bbdaecb2da59b686e2b377f401197d32a6af7e7fbe987

See more details on using hashes here.

File details

Details for the file polars_fastembed-0.1.13-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for polars_fastembed-0.1.13-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1cb73cf156856d95b8a59f42bd8f5c2a87a42a04324b3fcf396f66f22642c43b
MD5 b69ab39a0e450e693da7879e2cd07074
BLAKE2b-256 0e9b56c72d324ea68eb1e9c7d88514c24c1386b303613b6a2a505f896371d54b

See more details on using hashes here.

File details

Details for the file polars_fastembed-0.1.13-cp38-abi3-manylinux_2_28_i686.whl.

File metadata

File hashes

Hashes for polars_fastembed-0.1.13-cp38-abi3-manylinux_2_28_i686.whl
Algorithm Hash digest
SHA256 3b57281f7100c16ffdda0c50f44dc26a384667de270bdf4987ae7d1932ff2f8f
MD5 2b579f46dba77d81e0aff421aae935e5
BLAKE2b-256 3861dc0eee08ce76350f2169041729cba5b7c0c29a53cfa2db199d055973594d

See more details on using hashes here.

File details

Details for the file polars_fastembed-0.1.13-cp38-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for polars_fastembed-0.1.13-cp38-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3005c01a7d549dbc49e0dfae0623abe3839b0366ba65faccc4403a9dccf38b8f
MD5 d4ab36a2f6657b6a71c41a2ebb521e35
BLAKE2b-256 73913ba612c863a597d6848cc4f0ec1dc1e557cd85127b0adb00f0b3f8647a8e

See more details on using hashes here.

File details

Details for the file polars_fastembed-0.1.13-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for polars_fastembed-0.1.13-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d8491a5936623959441f8405f10f8dd9607422f671184af27fd4ea5addf529fe
MD5 bddfd3a07b75a2061a7d840d0f27107f
BLAKE2b-256 a8ea4ac91f9d198688263c1403e4e9d4cb7e0cd2f59ac8fae97705ae21c78546

See more details on using hashes here.

File details

Details for the file polars_fastembed-0.1.13-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for polars_fastembed-0.1.13-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 307937d04b65fd5d8df6579c129104b78c106e0bbfa74692ee0b9595cd653bbe
MD5 922fc1fc7557e703e8c3b103c485d3e1
BLAKE2b-256 9d066728869e67be827ab9fc83db07c3f973fc61bd77de916d47d02970a1a09b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page