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[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)

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.16.tar.gz (122.3 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.16-cp38-abi3-win_amd64.whl (8.2 MB view details)

Uploaded CPython 3.8+Windows x86-64

polars_fastembed-0.1.16-cp38-abi3-manylinux_2_28_i686.whl (15.8 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.28+ i686

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

Uploaded CPython 3.8+macOS 11.0+ ARM64

polars_fastembed-0.1.16-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.16.tar.gz.

File metadata

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

File hashes

Hashes for polars_fastembed-0.1.16.tar.gz
Algorithm Hash digest
SHA256 64ec1e8774f7a1bb57cee8be935ad9e5ad76c4ff4f4e632442f6ac2175169f95
MD5 58be957ab05906c7e0284696dfe60a67
BLAKE2b-256 afc5428325058ecb6c5c8d5cac73d47f067ef236ff6bd336e45a5a8d97b9793a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_fastembed-0.1.16-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c18e075953faf27126fab93cc204de73f1f40c296dc83c2129b9ddc1e6d29014
MD5 2b32ef0fc580c4ec6f3e6d577887feea
BLAKE2b-256 81ff2fa11ac964ef284dd6b731ea58f88e6843218ff70fea6c5a8ee1d2ec8ba3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_fastembed-0.1.16-cp38-abi3-manylinux_2_28_i686.whl
Algorithm Hash digest
SHA256 c37254d14f9116b56e1599f3f9daeef6ae42c79d0ebf1a30cab4fe775008f3f5
MD5 9cfa38d7738ad3f87246c7a9b6a99929
BLAKE2b-256 fdbf87a441c5c97fb547e705c1b6142889ece080e864089a87324c82efb76d5c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_fastembed-0.1.16-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 287c4daf3adf630eaf7f9cd63cadca805253cc1b12578957d72694f6d39c9452
MD5 a1b666072946fcb3bc0dc82559ada6e1
BLAKE2b-256 438f1a3420f347384520154387179d11ccfcaf95cc0b9b85c9f6000393866b23

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polars_fastembed-0.1.16-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ce1c07cea94fbd2aa120c1faa004bd53c88fefa93f6f49c681ddda03fb3ee1bb
MD5 c17cf84692ece34c2b80cc4e078a6e98
BLAKE2b-256 07d7025e4b675948d545be69920f0104fd334dda198742bff82589f59efff382

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