Skip to content

Commit 4dbc836

Browse files
authored
feat: Unify tokenizer API and add support for pdb.icu and pdb.edge_ngram (#53)
1 parent abb42f3 commit 4dbc836

30 files changed

Lines changed: 431 additions & 785 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989

9090
services:
9191
paradedb:
92-
image: paradedb/paradedb:0.22.0-pg${{ matrix.postgres-version }}
92+
image: paradedb/paradedb:0.23.0-pg${{ matrix.postgres-version }}
9393
ports:
9494
- 5432:5432
9595
env:

.github/workflows/schema-compat.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ jobs:
3838
with:
3939
python-version: "3.13"
4040

41+
- name: Set up uv
42+
uses: astral-sh/setup-uv@v7
43+
with:
44+
enable-cache: true
45+
4146
- name: Run Schema Compatibility Check
4247
env:
4348
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44-
run: python scripts/check_schema_compat.py ${{ env.PARADEDB_VERSION }}
49+
run: uv run --no-sync scripts/check_schema_compat.py ${{ env.PARADEDB_VERSION }}
4550

4651
integration-tests:
4752
name: Integration Tests

api.json renamed to api.json5

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"PDB_TYPE_TOKENIZER_SOURCE_CODE": "pdb.source_code",
5353
"PDB_TYPE_TOKENIZER_UNICODE_WORDS": "pdb.unicode_words",
5454
"PDB_TYPE_TOKENIZER_WHITESPACE": "pdb.whitespace",
55-
"PDB_TYPE_TOKENIZER_ICU": "pdb.icu"
55+
"PDB_TYPE_TOKENIZER_ICU": "pdb.icu",
56+
"PDB_TYPE_TOKENIZER_EDGE_NGRAM": "pdb.edge_ngram"
5657
}
5758
}

apiignore.json renamed to apiignore.json5

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
"pdb.alias_out_safe",
2020
"pdb.alias_recv",
2121
"pdb.alias_send",
22+
23+
// These functions are implementation details of tokenizers that the ORM
24+
// doesn't need to interact with
2225
"pdb.chinese_compatible_in",
2326
"pdb.chinese_compatible_out",
2427
"pdb.chinese_compatible_recv",
@@ -71,6 +74,16 @@
7174
"pdb.whitespace_out",
7275
"pdb.whitespace_recv",
7376
"pdb.whitespace_send",
77+
"pdb.edge_ngram_in",
78+
"pdb.edge_ngram_out",
79+
"pdb.edge_ngram_recv",
80+
"pdb.edge_ngram_send",
81+
"pdb.json_to_edge_ngram",
82+
"pdb.jsonb_to_edge_ngram",
83+
"pdb.text_array_to_edge_ngram",
84+
"pdb.tokenize_edge_ngram",
85+
"pdb.uuid_to_edge_ngram",
86+
"pdb.varchar_array_to_edge_ngram",
7487

7588
"pdb.bigint_array_to_alias",
7689
"pdb.bigint_to_alias",

examples/autocomplete/setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from sqlalchemy.engine import Engine
77
from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column
88

9+
from paradedb import tokenizer
910
from paradedb.sqlalchemy import indexing
1011

1112

@@ -34,12 +35,12 @@ class Product(Base):
3435
Index(
3536
"products_autocomplete_bm25_idx",
3637
indexing.BM25Field(Product.id),
37-
indexing.BM25Field(Product.description, tokenizer=indexing.tokenize.unicode(lowercase=True)),
38+
indexing.BM25Field(Product.description),
3839
indexing.BM25Field(
3940
Product.description,
40-
tokenizer=indexing.tokenize.ngram(min_gram=3, max_gram=8, prefix_only=True, alias="description_ngram"),
41+
tokenizer=tokenizer.ngram(3, 8, options={"prefix_only": True, "alias": "description_ngram"}),
4142
),
42-
indexing.BM25Field(Product.category, tokenizer=indexing.tokenize.literal()),
43+
indexing.BM25Field(Product.category, tokenizer=tokenizer.literal()),
4344
indexing.BM25Field(Product.rating),
4445
postgresql_using="bm25",
4546
postgresql_with={"key_field": "id"},

examples/faceted_search/setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from sqlalchemy.engine import Engine
77
from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column
88

9+
from paradedb import tokenizer
910
from paradedb.sqlalchemy import indexing
1011

1112

@@ -34,8 +35,8 @@ class Product(Base):
3435
Index(
3536
"products_facets_bm25_idx",
3637
indexing.BM25Field(Product.id),
37-
indexing.BM25Field(Product.description, tokenizer=indexing.tokenize.unicode(lowercase=True)),
38-
indexing.BM25Field(Product.category, tokenizer=indexing.tokenize.literal()),
38+
indexing.BM25Field(Product.description),
39+
indexing.BM25Field(Product.category, tokenizer=tokenizer.literal()),
3940
indexing.BM25Field(Product.rating),
4041
postgresql_using="bm25",
4142
postgresql_with={"key_field": "id"},

examples/hybrid_rrf/setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from sqlalchemy.engine import Engine
77
from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column
88

9+
from paradedb import tokenizer
910
from paradedb.sqlalchemy import indexing
1011

1112

@@ -34,8 +35,8 @@ class Product(Base):
3435
Index(
3536
"products_hybrid_rrf_bm25_idx",
3637
indexing.BM25Field(Product.id),
37-
indexing.BM25Field(Product.description, tokenizer=indexing.tokenize.unicode(lowercase=True)),
38-
indexing.BM25Field(Product.category, tokenizer=indexing.tokenize.literal()),
38+
indexing.BM25Field(Product.description),
39+
indexing.BM25Field(Product.category, tokenizer=tokenizer.literal()),
3940
indexing.BM25Field(Product.rating),
4041
postgresql_using="bm25",
4142
postgresql_with={"key_field": "id"},

examples/more_like_this/setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from sqlalchemy.engine import Engine
77
from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column
88

9+
from paradedb import tokenizer
910
from paradedb.sqlalchemy import indexing
1011

1112

@@ -34,8 +35,8 @@ class Product(Base):
3435
Index(
3536
"products_mlt_bm25_idx",
3637
indexing.BM25Field(Product.id),
37-
indexing.BM25Field(Product.description, tokenizer=indexing.tokenize.unicode(lowercase=True)),
38-
indexing.BM25Field(Product.category, tokenizer=indexing.tokenize.literal()),
38+
indexing.BM25Field(Product.description),
39+
indexing.BM25Field(Product.category, tokenizer=tokenizer.literal()),
3940
indexing.BM25Field(Product.rating),
4041
postgresql_using="bm25",
4142
postgresql_with={"key_field": "id"},

examples/quickstart/setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from sqlalchemy.engine import Engine
77
from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column
88

9+
from paradedb import tokenizer
910
from paradedb.sqlalchemy import indexing
1011

1112

@@ -34,8 +35,8 @@ class Product(Base):
3435
Index(
3536
"products_bm25_idx",
3637
indexing.BM25Field(Product.id),
37-
indexing.BM25Field(Product.description, tokenizer=indexing.tokenize.unicode(lowercase=True)),
38-
indexing.BM25Field(Product.category, tokenizer=indexing.tokenize.literal()),
38+
indexing.BM25Field(Product.description),
39+
indexing.BM25Field(Product.category, tokenizer=tokenizer.literal()),
3940
indexing.BM25Field(Product.rating),
4041
postgresql_using="bm25",
4142
postgresql_with={"key_field": "id"},

examples/rag/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Document(Base):
3030
Index(
3131
"documents_bm25_idx",
3232
indexing.BM25Field(Document.id),
33-
indexing.BM25Field(Document.content, tokenizer=indexing.tokenize.unicode(lowercase=True)),
33+
indexing.BM25Field(Document.content),
3434
postgresql_using="bm25",
3535
postgresql_with={"key_field": "id"},
3636
)

0 commit comments

Comments
 (0)