Skip to content

Commit c8aa2db

Browse files
committed
Remove index_schema API and prune legacy tokenizer config branch
1 parent af92ff0 commit c8aa2db

6 files changed

Lines changed: 53 additions & 18 deletions

File tree

README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,39 @@ products_bm25_idx = Index(
7070
)
7171
```
7272

73+
Tokenizer configs can use a Django/Rails-style structured shape:
74+
75+
```python
76+
products_bm25_idx = Index(
77+
"products_bm25_idx",
78+
indexing.BM25Field(Product.id),
79+
indexing.BM25Field(
80+
Product.description,
81+
tokenizer=indexing.tokenize.from_config(
82+
{
83+
"tokenizer": "simple",
84+
"filters": ["lowercase", "stemmer"],
85+
"stemmer": "english",
86+
"alias": "description_simple",
87+
}
88+
),
89+
),
90+
indexing.BM25Field(
91+
Product.description,
92+
tokenizer=indexing.tokenize.from_config(
93+
{
94+
"tokenizer": "ngram",
95+
"args": [3, 8],
96+
"named_args": {"prefix_only": True},
97+
"alias": "description_ngram",
98+
}
99+
),
100+
),
101+
postgresql_using="bm25",
102+
postgresql_with={"key_field": "id"},
103+
)
104+
```
105+
73106
## Query APIs
74107

75108
- Basic predicates: `match_all`, `match_any`, `term`, `phrase`, `fuzzy`, `regex`, `all`
@@ -108,8 +141,24 @@ Usage:
108141

109142
```python
110143
op.create_bm25_index("products_bm25_idx", "products", ["id", "description"], key_field="id")
144+
# Tokenizer-aware expressions are supported too:
145+
op.create_bm25_index(
146+
"products_bm25_idx",
147+
"products",
148+
["id", "((description)::pdb.simple('alias=description_simple,lowercase=true'))"],
149+
key_field="id",
150+
)
151+
# Schema-aware operations:
152+
op.create_bm25_index(
153+
"products_bm25_idx",
154+
"products",
155+
["id", "description"],
156+
key_field="id",
157+
table_schema="search",
158+
)
111159
op.reindex_bm25("products_bm25_idx", concurrently=True)
112-
op.drop_bm25_index("products_bm25_idx", if_exists=True)
160+
op.reindex_bm25("products_bm25_idx", concurrently=True, schema="search")
161+
op.drop_bm25_index("products_bm25_idx", if_exists=True, schema="search")
113162
```
114163

115164
## Validation and Guardrails

paradedb/sqlalchemy/alembic.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@ def __init__(
3535
key_field: str,
3636
*,
3737
table_schema: str | None = None,
38-
index_schema: str | None = None,
3938
) -> None:
4039
self.index_name = index_name
4140
self.table_name = table_name
4241
self.expressions = expressions
4342
self.key_field = key_field
4443
self.table_schema = table_schema
45-
self.index_schema = index_schema
4644

4745
@classmethod
4846
def create_bm25_index(
@@ -54,7 +52,6 @@ def create_bm25_index(
5452
*,
5553
key_field: str,
5654
table_schema: str | None = None,
57-
index_schema: str | None = None,
5855
) -> MigrateOperation:
5956
return operations.invoke(
6057
cls(
@@ -63,7 +60,6 @@ def create_bm25_index(
6360
expressions,
6461
key_field,
6562
table_schema=table_schema,
66-
index_schema=index_schema,
6763
)
6864
)
6965

@@ -89,8 +85,6 @@ def _render_create_bm25_index_op(autogen_context, op: CreateBM25IndexOp) -> str:
8985
]
9086
if op.table_schema is not None:
9187
parts.append(f"table_schema={op.table_schema!r}")
92-
if op.index_schema is not None:
93-
parts.append(f"index_schema={op.index_schema!r}")
9488
return f"op.create_bm25_index({', '.join(parts)})"
9589

9690

@@ -298,7 +292,6 @@ def _compare_bm25_indexes(autogen_context, upgrade_ops, schemas) -> PriorityDisp
298292
expressions=expressions,
299293
key_field=key_field,
300294
table_schema=key[0],
301-
index_schema=key[0],
302295
)
303296
)
304297
else:
@@ -313,7 +306,6 @@ def _compare_bm25_indexes(autogen_context, upgrade_ops, schemas) -> PriorityDisp
313306
expressions=expressions,
314307
key_field=key_field,
315308
table_schema=key[0],
316-
index_schema=key[0],
317309
)
318310
)
319311

paradedb/sqlalchemy/indexing.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,6 @@ def custom(
306306
def from_config(config: Mapping[str, Any]) -> TokenizerSpec:
307307
if not isinstance(config, Mapping):
308308
raise InvalidArgumentError("tokenizer config must be a mapping")
309-
if "options" in config:
310-
raise InvalidArgumentError("tokenizer config uses deprecated 'options'. Use 'named_args' instead.")
311309

312310
allowed_keys = {"tokenizer", "args", "named_args", "filters", "stemmer", "alias"}
313311
unknown = set(config.keys()) - allowed_keys

tests/integration/test_alembic_integration.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ def test_alembic_create_reindex_drop_with_schema(engine):
9999
["id", "description"],
100100
key_field="id",
101101
table_schema=schema,
102-
index_schema=schema,
103102
)
104103

105104
exists = conn.execute(
@@ -378,7 +377,6 @@ def test_autogenerate_emits_schema_on_create_for_non_default_schema(engine):
378377
create_ops = [op for op in upgrade_ops.ops if isinstance(op, pdb_alembic.CreateBM25IndexOp)]
379378
op = next(o for o in create_ops if o.index_name == _AG_SCHEMA_IDX)
380379
assert op.table_schema == _AG_SCHEMA
381-
assert op.index_schema == _AG_SCHEMA
382380
finally:
383381
with engine.begin() as conn:
384382
conn.execute(text(f'DROP SCHEMA IF EXISTS "{_AG_SCHEMA}" CASCADE'))

tests/unit/test_alembic_unit.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def test_create_drop_reindex_sql_generation_with_schema():
6666
expressions=["id", "description"],
6767
key_field="id",
6868
table_schema="analytics",
69-
index_schema="analytics",
7069
)
7170
pdb_alembic._create_bm25_index_impl(ops, create_op)
7271
assert ops.sql[-1] == (
@@ -120,11 +119,10 @@ def test_alembic_renderers_registered_and_emit_python():
120119
expressions=["id", "description"],
121120
key_field="id",
122121
table_schema="analytics",
123-
index_schema="analytics",
124122
),
125123
)
126124
assert create_lines_with_schema == [
127-
"op.create_bm25_index('products_bm25_idx', 'products', ['id', 'description'], key_field='id', table_schema='analytics', index_schema='analytics')"
125+
"op.create_bm25_index('products_bm25_idx', 'products', ['id', 'description'], key_field='id', table_schema='analytics')"
128126
]
129127

130128

tests/unit/test_indexing_unit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ def test_tokenizer_from_config_unknown_key_raises():
257257
tokenize.from_config({"tokenizer": "simple", "unknown": True})
258258

259259

260-
def test_tokenizer_from_config_options_deprecated_raises():
261-
with pytest.raises(InvalidArgumentError, match="deprecated 'options'"):
260+
def test_tokenizer_from_config_options_key_raises_as_unknown():
261+
with pytest.raises(InvalidArgumentError, match="Unknown tokenizer config keys"):
262262
tokenize.from_config({"tokenizer": "simple", "options": {"lowercase": True}})
263263

264264

0 commit comments

Comments
 (0)