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.9.tar.gz (109.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.9-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl (7.2 MB view details)

Uploaded PyPymanylinux: glibc 2.28+ ARM64

polars_fastembed-0.1.9-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl (7.2 MB view details)

Uploaded PyPymanylinux: glibc 2.28+ ARM64

polars_fastembed-0.1.9-cp38-abi3-win_amd64.whl (5.2 MB view details)

Uploaded CPython 3.8+Windows x86-64

polars_fastembed-0.1.9-cp38-abi3-manylinux_2_28_i686.whl (7.4 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.28+ i686

polars_fastembed-0.1.9-cp38-abi3-manylinux_2_28_aarch64.whl (7.2 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.28+ ARM64

polars_fastembed-0.1.9-cp38-abi3-macosx_11_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

polars_fastembed-0.1.9-cp38-abi3-macosx_10_12_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for polars_fastembed-0.1.9.tar.gz
Algorithm Hash digest
SHA256 8a94f6bd50681dd2974ef3bb1475c99b5238d3b60ef56c11cacd9e0be370624a
MD5 edfa6b3cf31632b968e4cec0d6ac62e1
BLAKE2b-256 c83bb5d957faf42fe09872ffff283880a0fafc7fe8f00d5a1a1c2ef15be41811

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_fastembed-0.1.9-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d7e2503de375cd808f30ec919a7aa37ceab41eefe7486d9d8d5910f2f53387b0
MD5 bd6c706952ffc3715a340dbe8073d795
BLAKE2b-256 fa6bd7af30f1e263a70bab66b494471e227785fe9423c001c049fa977b8266c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_fastembed-0.1.9-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 190e0a12b349755b9de51b60a6b8487b4a11c34bc011598a6ccf4338230c9528
MD5 622a8ea9390955caa8469f34f5a0d6cc
BLAKE2b-256 327b984d41602a32afa353c6b75a0f09e567e4cb16f5f98f84ac840a8145aac0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_fastembed-0.1.9-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 606610c105ef89086fa0d7295cc3f5cacadf8c7aef202c02cf0f8fdc9442533a
MD5 f33944b4c884410faf3a23b663916a74
BLAKE2b-256 eafc0849d9f46f23b786f3dfacb5dce73c284027791a08767e4b7ae5646c9cf7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_fastembed-0.1.9-cp38-abi3-manylinux_2_28_i686.whl
Algorithm Hash digest
SHA256 9086771ee7251cb981e41f4dcf4b6620d3b3e77c9556e55f6d8bc61c0d08e0bb
MD5 3dd7d5f77f7ab52355a265230dfd55ca
BLAKE2b-256 e24fe69b38c553a90dd58b372248e223794ab69ca62c544a500b28f2072cf291

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_fastembed-0.1.9-cp38-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ff3cf256d24529f54a59cbb4102e71f27ef7cc0f61ade98c060dfa344f353a63
MD5 a90c960c3e281d3131bcb738c6fb9ec9
BLAKE2b-256 b6614d9e11a672f2fc54b6cc463c3f166e76e23a32a62f110c84fd9c2b3da20a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_fastembed-0.1.9-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3a207b143fba33ad1eccba76b159696af3b5bd512c78b27cc9105903bd235f6c
MD5 a4417befa585bdbdb9d0290d79b195e6
BLAKE2b-256 cf2de2ad871653a00d00ef33df204151c3aeb4669e0b38001c1beb98014ab6f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_fastembed-0.1.9-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ab671083f1bf91f42ebe56c94f580767adc1c7d2e8431161292a1faaaad40aeb
MD5 5ae16936e4ee6465a6df03d84c5e6503
BLAKE2b-256 92389b6edd5b000ad4119d7140eafbabdf2cbc3035e35e99b8c29fd718e97b60

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