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.8.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.8-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl (7.2 MB view details)

Uploaded PyPymanylinux: glibc 2.28+ ARM64

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

Uploaded PyPymanylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.8+Windows x86-64

polars_fastembed-0.1.8-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.8-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.8-cp38-abi3-macosx_11_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

polars_fastembed-0.1.8-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.8.tar.gz.

File metadata

  • Download URL: polars_fastembed-0.1.8.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.8.tar.gz
Algorithm Hash digest
SHA256 95aca5f1ee6df2e1cf1aaa63c947adb36c4ff55ccdccf1fa491b27c7cb62d3fe
MD5 ba7607b4e56f7160bfa2840211e57eee
BLAKE2b-256 8ffbb8b8d50aa0618315a6f20102e4d9a8f30bae8fb5b5c790ea0d6c2bc32dae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_fastembed-0.1.8-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b4162896938de50022c0d005638c09e074a29e60c4a81e2a208b0fdeeccf95f8
MD5 cd82dffccb64d8095a1489bedaa30b81
BLAKE2b-256 4a95d2d9ece781562683d4b278afcc74ee801e353805c8e6a20d0d4f3d4bd887

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_fastembed-0.1.8-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ecdbd4695676d4d4a0d888d899ddb7e059519f7e8816091d8795899045cbe970
MD5 753b8ec632b4c05fee5254d83521df67
BLAKE2b-256 bb769a670d7f4e7c6527d15f4c171bf188b01b7d370e73fb53cb71f6caf3bfbc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_fastembed-0.1.8-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d72616f1d365af0b5dac65aeed6b7f5fa08d34fbde4e0fdefa469ae49ca9b52c
MD5 dc845a491f82b87065005d3e21ef643a
BLAKE2b-256 b587eb3f3c613e73e874a4728aad6a71e83a87d2a7be33cb4ffbbf448afabfb1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_fastembed-0.1.8-cp38-abi3-manylinux_2_28_i686.whl
Algorithm Hash digest
SHA256 e5f843c622a3f776b398430e4fd0fd1503b39b393c8913dd156a6a6c5f5062bc
MD5 1f9963acc10a7df9a7e82621626fb749
BLAKE2b-256 855bc10812e6625686b0933301d7ba2277a137ff899ef20acf52b61f41d2d7c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_fastembed-0.1.8-cp38-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f296c173065ac3a54d939f2ab26cf8c7a2eb6e7723295f4ec8f8beb87726f684
MD5 a5f3be45128a87b6e2110e859c8bb3f1
BLAKE2b-256 e8786fbffdb57be9264c186b3d006b6fc04d9cc468558f19d6c4cf2cf0bd5746

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_fastembed-0.1.8-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 70b0dcd0914e4d1d7a6b9fb98bfd83b654c2d595a1ceecf91684e5a4856c2da4
MD5 5c8d7cea09fa3ae3604dfb38773dd6b8
BLAKE2b-256 cf80a29eccfe6da7ec7864a57d5b88b1fb3b6a676a41b5f03be5496260e9685f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_fastembed-0.1.8-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 99cdfa8ac19e683afd833726fa9214dc2f572989680a4243dcf2d5a9351a34b5
MD5 58d13ebe8eb659fb8cd6f25c1cab25d7
BLAKE2b-256 effe82869295386fe0860052628b6fc50cdac28073b849e573072c222b798077

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