MCPcopy Create free account
hub / github.com/alibaba/zvec / Query

Class Query

python/zvec/model/param/query.py:50–164  ·  view source on GitHub ↗

Represents a search query for a specific field in a collection. A `Query` can be constructed for either vector search or full-text search, but not both simultaneously. For vector search, provide `id` or `vector` (and optionally `param`). For FTS, provide `fts`. Attributes:

Source from the content-addressed store, hash-verified

48
49@dataclass(frozen=True)
50class Query:
51 """Represents a search query for a specific field in a collection.
52
53 A `Query` can be constructed for either vector search or full-text search,
54 but not both simultaneously.
55
56 For vector search, provide `id` or `vector` (and optionally `param`).
57 For FTS, provide `fts`.
58
59 Attributes:
60 field_name (str): Name of the field to query.
61 id (Optional[str], optional): Document ID to fetch vector from. Default is None.
62 vector (VectorType, optional): Explicit query vector. Default is None.
63 param (Optional[Union[HnswQueryParam, HnswRabitqQueryParam, IVFQueryParam, IvfRabitqQueryParam, VamanaQueryParam, FtsQueryParam]], optional):
64 Index-specific query parameters. Default is None.
65 fts (Optional[Fts], optional): Full-text search parameters. Default is None.
66
67 Examples:
68 >>> import zvec
69 >>> # Query by ID
70 >>> q1 = zvec.Query(field_name="embedding", id="doc123")
71 >>> # Query by vector
72 >>> q2 = zvec.Query(
73 ... field_name="embedding",
74 ... vector=[0.1, 0.2, 0.3],
75 ... param=HnswQueryParam(ef=300)
76 ... )
77 >>> # FTS query
78 >>> q3 = zvec.Query(
79 ... field_name="content",
80 ... fts=Fts(match_string="machine learning")
81 ... )
82 >>> # FTS query with custom operator
83 >>> q4 = zvec.Query(
84 ... field_name="content",
85 ... fts=Fts(match_string="machine learning"),
86 ... param=FtsQueryParam(default_operator="AND")
87 ... )
88 """
89
90 field_name: str
91 id: Optional[str] = None
92 vector: VectorType = None
93 param: Optional[
94 Union[
95 HnswQueryParam,
96 HnswRabitqQueryParam,
97 IVFQueryParam,
98 VamanaQueryParam,
99 IvfRabitqQueryParam,
100 FtsQueryParam,
101 ]
102 ] = None
103 fts: Optional[Fts] = None
104
105 def has_id(self) -> bool:
106 """Check if the query is based on a document ID.
107

Calls

no outgoing calls