Classes
LogicalExpr
Internal Instances of theLogicalExpr
class are used to represent logical expressions in TopK.
Usually created using logical constructors such as field()
, literal()
, etc.
Methods
is_null()
LogicalExpr
is_not_null()
LogicalExpr
abs()
LogicalExpr
ln()
LogicalExpr
exp()
LogicalExpr
sqrt()
LogicalExpr
square()
LogicalExpr
eq()
Parameter | Type |
---|---|
other | FlexibleExpr |
LogicalExpr
ne()
Parameter | Type |
---|---|
other | FlexibleExpr |
LogicalExpr
lt()
Parameter | Type |
---|---|
other | Ordered |
LogicalExpr
lte()
Parameter | Type |
---|---|
other | Ordered |
LogicalExpr
gt()
Parameter | Type |
---|---|
other | Ordered |
LogicalExpr
gte()
Parameter | Type |
---|---|
other | Ordered |
LogicalExpr
add()
Parameter | Type |
---|---|
other | Numeric |
LogicalExpr
sub()
Parameter | Type |
---|---|
other | Numeric |
LogicalExpr
mul()
Parameter | Type |
---|---|
other | Numeric |
LogicalExpr
div()
Parameter | Type |
---|---|
other | Numeric |
LogicalExpr
min()
Parameter | Type |
---|---|
other | Ordered |
LogicalExpr
max()
Parameter | Type |
---|---|
other | Ordered |
LogicalExpr
and_()
Parameter | Type |
---|---|
other | Boolish |
LogicalExpr
or_()
Parameter | Type |
---|---|
other | Boolish |
LogicalExpr
starts_with()
Parameter | Type |
---|---|
other | Stringy |
LogicalExpr
contains()
Parameter | Type |
---|---|
other | FlexibleExpr |
LogicalExpr
in_()
Parameter | Type |
---|---|
other | Iterable |
LogicalExpr
match_all()
Parameter | Type |
---|---|
other | StringyWithList |
LogicalExpr
match_any()
Parameter | Type |
---|---|
other | StringyWithList |
LogicalExpr
coalesce()
Parameter | Type |
---|---|
other | Numeric |
LogicalExpr
choose()
Parameter | Type |
---|---|
x | FlexibleExpr |
y | FlexibleExpr |
LogicalExpr
boost()
boost
value if the condition
is true.
Parameters
Parameter | Type |
---|---|
condition | FlexibleExpr |
boost | Numeric |
LogicalExpr
FunctionExpr
Internal Instances of theFunctionExpr
class are used to represent function expressions in TopK.
Usually created using function constructors such as fn.vector_distance()
, fn.semantic_similarity()
or fn.bm25_score()
.
TextExpr
Internal Instances of theTextExpr
class are used to represent text expressions in TopK.
Query
Methodsselect()
Query
filter()
Parameter | Type | |
---|---|---|
expr | LogicalExpr | TextExpr |
Query
topk()
Parameter | Type |
---|---|
expr | LogicalExpr |
k | int |
asc | bool |
Query
rerank()
Parameter | Type |
---|---|
model | Optional[str] |
query | Optional[str] |
fields | Sequence[str] |
topk_multiple | Optional[int] |
Query
count()
Query
fn
Thequery.fn
submodule exposes functions for creating function expressions such as fn.vector_distance()
, fn.semantic_similarity()
or fn.bm25_score()
.
Methods
vector_distance()
Parameter | Type | |||||
---|---|---|---|---|---|---|
field | str | |||||
vector | list[int] | list[float] | dict[int, float] | dict[int, int] | topk_sdk.data.SparseVector | topk_sdk.data.List |
skip_refine | bool |
FunctionExpr
semantic_similarity()
Parameter | Type |
---|---|
field | str |
query | str |
FunctionExpr
bm25_score()
FunctionExpr
Functions
field()
Parameter | Type |
---|---|
name | str |
LogicalExpr
select()
Example:
Create a select stage of a query.Query
filter()
Parameter | Type | |
---|---|---|
expr | LogicalExpr | TextExpr |
Query
literal()
Parameter | Type |
---|---|
value | Any |
LogicalExpr
match()
- Match on multiple terms
- Match only on specific fields
- Use weights to prioritize certain terms
Parameter | Type | |
---|---|---|
token | str | |
field | str | None |
weight | float | |
all | bool |
LogicalExpr
not_()
Parameter | Type |
---|---|
expr | LogicalExpr |
LogicalExpr
abs()
Parameter | Type |
---|---|
expr | LogicalExpr |
LogicalExpr
all()
Parameter | Type |
---|---|
exprs | Sequence[LogicalExpr ] |
LogicalExpr
any()
Parameter | Type |
---|---|
exprs | Sequence[LogicalExpr ] |
LogicalExpr
min()
Parameter | Type |
---|---|
left | Ordered |
right | Ordered |
LogicalExpr
max()
Parameter | Type |
---|---|
left | Ordered |
right | Ordered |
LogicalExpr
Type Aliases
FlexibleExpr
LogicalExpr
Numeric
LogicalExpr
Ordered
LogicalExpr
Boolish
LogicalExpr
Stringy
LogicalExpr
StringyWithList
LogicalExpr
Iterable
topk_sdk.data.List
| LogicalExpr