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

Class Query

python/zvec/model/param/query.py:49–162  ·  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

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

Calls

no outgoing calls