> ## Documentation Index
> Fetch the complete documentation index at: https://www.paradedb.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Text

> Configure text tokenization, BM25 scoring, and query optimizations

## Tokenizers

By default, text columns are tokenized using the [unicode](https://www.paradedb.com/docs/reference/tokenizers/available-tokenizers/unicode.md) tokenizer, which splits text according to the
Unicode segmentation standard. Because index creation is a time-consuming operation, we recommend experimenting with the [available tokenizers](https://www.paradedb.com/docs/reference/tokenizers/overview.md)
to find the most suitable one before running `CREATE INDEX`.

For instance, if a column contains multiple languages, the ICU tokenizer may be more appropriate.

```sql SQL theme={null}
CREATE INDEX search_idx ON mock_items
USING paradedb (id, (description::pdb.icu), category);
```

```ts Drizzle theme={null}
import { indexing, tokenizer } from "@paradedb/drizzle-paradedb";

indexing
  .paradedbIndex("search_idx")
  .on(
    mockItems.id,
    indexing.paradedbField(mockItems.description, tokenizer.icu()),
    mockItems.category,
  );
```

```python Django theme={null}
from django.db import connection
from paradedb.indexes import ParadeDBIndex
from paradedb.search import Tokenizer

with connection.schema_editor() as schema_editor:
    schema_editor.add_index(
        MockItem,
        ParadeDBIndex(
            fields={
                "id": {},
                "description": {"tokenizer": Tokenizer.icu()},
                "category": {},
            },
            name="search_idx",
        ),
    )
```

```python SQLAlchemy theme={null}
from sqlalchemy import Index
from paradedb.sqlalchemy import indexing, tokenizer

idx = Index(
    "search_idx",
    indexing.ParadeDBField(MockItem.id),
    indexing.ParadeDBField(
        MockItem.description,
        tokenizer=tokenizer.icu(),
    ),
    indexing.ParadeDBField(MockItem.category),
    postgresql_using="paradedb",
)

with engine.begin() as conn:
    idx.create(conn)
```

```ruby Rails theme={null}
ActiveRecord::Base.connection.add_paradedb_index(
  :mock_items,
  fields: {
    id: {},
    description: { tokenizer: ParadeDB::Tokenizer.icu() },
    category: {}
  },
  name: :search_idx
)
```

```cs EF Core theme={null}
modelBuilder.Entity<MockItem>()
    .HasParadeDbIndex("search_idx", e => e.Id)
    .HasField(e => e.Description, Tokenizer.Icu())
    .HasField(e => e.Category);
```

## Token Filters

After tokens are created, [token filters](https://www.paradedb.com/docs/reference/token-filters/overview.md) can be configured to apply further processing like lowercasing, stemming, or unaccenting.
For example, the following code block adds English stemming to `description`:

```sql SQL theme={null}
CREATE INDEX search_idx ON mock_items
USING paradedb (id, (description::pdb.simple('stemmer=english')), category);
```

```ts Drizzle theme={null}
import { indexing, tokenizer } from "@paradedb/drizzle-paradedb";

indexing
  .paradedbIndex("search_idx")
  .on(
    mockItems.id,
    indexing.paradedbField(
      mockItems.description,
      tokenizer.simple({ stemmer: "english" }),
    ),
    mockItems.category,
  );
```

```python Django theme={null}
from django.db import connection
from paradedb.indexes import ParadeDBIndex
from paradedb.search import Tokenizer

with connection.schema_editor() as schema_editor:
    schema_editor.add_index(
        MockItem,
        ParadeDBIndex(
            fields={
                "id": {},
                "description": {
                    "tokenizer": Tokenizer.simple(
                        options={"stemmer": "english"}
                    ),
                },
                "category": {},
            },
            name="search_idx",
        ),
    )
```

```python SQLAlchemy theme={null}
from sqlalchemy import Index
from paradedb.sqlalchemy import indexing, tokenizer

idx = Index(
    "search_idx",
    indexing.ParadeDBField(MockItem.id),
    indexing.ParadeDBField(
        MockItem.description,
        tokenizer=tokenizer.simple(options={"stemmer": "english"}),
    ),
    indexing.ParadeDBField(MockItem.category),
    postgresql_using="paradedb",
)

with engine.begin() as conn:
    idx.create(conn)
```

```ruby Rails theme={null}
ActiveRecord::Base.connection.add_paradedb_index(
  :mock_items,
  fields: {
    id: {},
    description: {
      tokenizer: ParadeDB::Tokenizer.simple(options: { stemmer: "english" })
    },
    category: {}
  },
  name: :search_idx
)
```

```cs EF Core theme={null}
modelBuilder.Entity<MockItem>()
    .HasParadeDbIndex("search_idx", e => e.Id)
    .HasField(e => e.Description, Tokenizer.Simple(new() { ["stemmer"] = "english" }))
    .HasField(e => e.Category);
```

## BM25 Parameters

> [!NOTE]
>
> Tuning BM25 parameters is not necessary for most use cases.

BM25 uses two parameters, `k1` and `b`, to control how term frequency and field length affect relevance scores. You can configure them independently for each field when creating an index.

| Parameter | Default | Accepted Range | Effect |
| - | - | - | - |
| `k1` | `1.2` | `0` to `100`, inclusive | Controls term frequency saturation. Lower values reduce the benefit of repeated query terms; higher values give them more weight. At `0`, repeated occurrences add no weight, and `b` has no effect. |
| `b` | `0.75` | `0` to `1`, inclusive | Controls field length normalization relative to the field's average length. Higher values penalize longer fields more strongly. At `0`, normalization is disabled; at `1`, it is fully applied. |

Pass `k1` and `b` as options to a field's [tokenizer](https://www.paradedb.com/docs/reference/tokenizers/overview.md). In this example, the `description` field uses lower values to reduce the influence of repeated terms and field length. The `category` field gives repeated terms more weight while keeping the default length normalization.

```sql SQL theme={null}
CREATE INDEX search_idx ON mock_items
USING paradedb (
  id,
  (description::pdb.simple('k1=0.9', 'b=0.3')),
  (category::pdb.simple('k1=1.5', 'b=0.75'))
);
```

```ts Drizzle theme={null}
import { indexing, tokenizer } from "@paradedb/drizzle-paradedb";

indexing
  .paradedbIndex("search_idx")
  .on(
    mockItems.id,
    indexing.paradedbField(
      mockItems.description,
      tokenizer.simple({ k1: 0.9, b: 0.3 }),
    ),
    indexing.paradedbField(
      mockItems.category,
      tokenizer.simple({ k1: 1.5, b: 0.75 }),
    ),
  );
```

```python Django theme={null}
from django.db import connection
from paradedb.indexes import ParadeDBIndex
from paradedb.search import Tokenizer

with connection.schema_editor() as schema_editor:
    schema_editor.add_index(
        MockItem,
        ParadeDBIndex(
            fields={
                "id": {},
                "description": {"tokenizer": Tokenizer.simple(options={"k1": 0.9, "b": 0.3})},
                "category": {"tokenizer": Tokenizer.simple(options={"k1": 1.5, "b": 0.75})},
            },
            name="search_idx",
        ),
    )
```

```python SQLAlchemy theme={null}
from sqlalchemy import Index
from paradedb.sqlalchemy import indexing, tokenizer

idx = Index(
    "search_idx",
    indexing.ParadeDBField(MockItem.id),
    indexing.ParadeDBField(
        MockItem.description,
        tokenizer=tokenizer.simple(options={"k1": 0.9, "b": 0.3}),
    ),
    indexing.ParadeDBField(
        MockItem.category,
        tokenizer=tokenizer.simple(options={"k1": 1.5, "b": 0.75}),
    ),
    postgresql_using="paradedb",
)

with engine.begin() as conn:
    idx.create(conn)
```

```ruby Rails theme={null}
ActiveRecord::Base.connection.add_paradedb_index(
  :mock_items,
  fields: {
    id: {},
    description: { tokenizer: ParadeDB::Tokenizer.simple(options: { k1: 0.9, b: 0.3 }) },
    category: { tokenizer: ParadeDB::Tokenizer.simple(options: { k1: 1.5, b: 0.75 }) }
  },
  name: :search_idx
)
```

```cs EF Core theme={null}
modelBuilder.Entity<MockItem>()
    .HasParadeDbIndex("search_idx", e => e.Id)
    .HasField(e => e.Description, Tokenizer.Simple(new() { ["k1"] = 0.9f, ["b"] = 0.3f }))
    .HasField(e => e.Category, Tokenizer.Simple(new() { ["k1"] = 1.5f, ["b"] = 0.75f }));
```

You can set either parameter on its own or both together. Omitted parameters keep their defaults, and queries automatically use the values configured in the index.

## Faster BM25 Queries

> [!NOTE]
>
> This feature is available in versions `0.26.0` and above.

Top K queries ordered by
[BM25 score](https://www.paradedb.com/docs/reference/full-text/score.md) can be sped up by setting `pnorms=true`
when creating your index, at the cost of a larger index and longer builds.

### Enable the Optimization

Set `pnorms=true` on the [tokenizer](https://www.paradedb.com/docs/reference/tokenizers/overview.md) cast for each
text field used in BM25 scoring. The option defaults to `false`. This example
enables it for `description`:

```sql SQL theme={null}
CREATE INDEX search_idx ON mock_items
USING paradedb (id, (description::pdb.unicode_words('pnorms=true')), category);
```

```ts Drizzle theme={null}
import { indexing, tokenizer } from "@paradedb/drizzle-paradedb";

indexing
  .paradedbIndex("search_idx")
  .on(
    mockItems.id,
    indexing.paradedbField(
      mockItems.description,
      tokenizer.unicodeWords({ pnorms: true }),
    ),
    mockItems.category,
  );
```

```python Django theme={null}
from django.db import connection
from paradedb.indexes import ParadeDBIndex
from paradedb.search import Tokenizer

with connection.schema_editor() as schema_editor:
    schema_editor.add_index(
        MockItem,
        ParadeDBIndex(
            fields={'id': {}, 'description': {'tokenizer': Tokenizer.unicode_words(options={"pnorms": True})}, 'category': {}},
            name="search_idx",
        ),
    )
```

```python SQLAlchemy theme={null}
from sqlalchemy import Index
from paradedb.sqlalchemy import indexing
from paradedb.sqlalchemy import tokenizer

idx = Index(
    "search_idx",
    indexing.ParadeDBField(MockItem.id),
    indexing.ParadeDBField(MockItem.description, tokenizer=tokenizer.unicode_words(options={"pnorms": True})),
    indexing.ParadeDBField(MockItem.category),
    postgresql_using="paradedb",
)

with engine.begin() as conn:
    idx.create(conn)
```

```ruby Rails theme={null}
ActiveRecord::Base.connection.add_paradedb_index(
  :mock_items,
  fields: {
    id: {},
    description: { tokenizer: ParadeDB::Tokenizer.unicode_words(options: { pnorms: true }) },
    category: {},
  },
  name: :search_idx
)
```

```cs EF Core theme={null}
modelBuilder.Entity<MockItem>()
    .HasParadeDbIndex("search_idx", e => e.Id)
    .HasField(e => e.Description, Tokenizer.Unicode(new() { ["pnorms"] = true }))
    .HasField(e => e.Category);
```

Queries automatically use the setting from the index:

```sql theme={null}
SELECT id, description, pdb.score(id)
FROM mock_items
WHERE description ||| 'shoes'
ORDER BY pdb.score(id) DESC
LIMIT 5;
```

This option is only supported for text fields. Existing indexes must be
[rebuilt](https://www.paradedb.com/docs/operate/index-maintenance/reindexing.md) with `pnorms=true` to enable it.

### Performance Tradeoff

BM25 scoring uses the length of each text field to help determine relevance.
Setting `pnorms=true` stores an extra, denser copy of this information where the scoring
process can read it more efficiently. Depending on the data and query, this can
make queries several times faster without changing scores or relevance ranking.

For each field with `pnorms` enabled, the extra storage is roughly one byte per
distinct term in each document, plus metadata. The extra data also increases
the work required to build and merge index segments. Enable `pnorms` on fields
where faster BM25 top K queries justify those costs.

## Faster Counts

> [!NOTE]
>
> This feature is available in versions `0.26.2` and above. Indexes built before
> `0.26.2` must be [rebuilt](https://www.paradedb.com/docs/operate/index-maintenance/reindexing.md) to receive
> this optimization.

ParadeDB can speed up eligible `COUNT(*)` queries that combine common search terms
with `AND` or `OR` by storing additional bitmap structures.

### Index Configuration

The `bitmap_postings` option on a [tokenizer](https://www.paradedb.com/docs/reference/tokenizers/overview.md) cast
defaults to `true`.

It is enabled by default because the storage overhead is usually very small.
If your workload does not require counts, you can disable it for a field with
`bitmap_postings=false`:

```sql theme={null}
CREATE INDEX search_idx ON mock_items
USING paradedb (id, (description::pdb.unicode_words('bitmap_postings=false')), category);
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.