qdrant_edge/edge/requests/query.rs
1use crate::common::types::ScoreType;
2use crate::segment::types::{Filter, SearchParams, WithPayloadInterface, WithVector};
3use crate::shard::query::ScoringQuery;
4
5/// Universal query over an edge shard: a scoring query with optional prefetch stages.
6#[derive(Clone, Debug, PartialEq)]
7pub struct QueryRequest {
8 /// Sub-requests resolved first; their results form the candidate set the top-level
9 /// `query` re-scores.
10 pub prefetches: Vec<Prefetch>,
11 /// How to score the candidates. `None` scrolls by id instead of scoring.
12 pub query: Option<ScoringQuery>,
13 /// Look only for points which satisfy these conditions.
14 pub filter: Option<Filter>,
15 /// Exclude results with a worse score than this.
16 pub score_threshold: Option<ScoreType>,
17 /// Max number of results to return.
18 pub limit: usize,
19 /// Offset of the first result to return. May be used to paginate results.
20 /// Note: large offset values may cause performance issues.
21 pub offset: usize,
22 /// Search params for when there is no prefetch.
23 pub params: Option<SearchParams>,
24 /// Options for specifying which vectors to include into the response. Default is false.
25 pub with_vector: WithVector,
26 /// Select which payload to return with the response. Default is false.
27 pub with_payload: WithPayloadInterface,
28}
29
30impl QueryRequest {
31 pub fn new(limit: usize) -> Self {
32 Self {
33 prefetches: Vec::new(),
34 query: None,
35 filter: None,
36 score_threshold: None,
37 limit,
38 offset: 0,
39 params: None,
40 with_vector: WithVector::Bool(false),
41 with_payload: WithPayloadInterface::Bool(false),
42 }
43 }
44}
45
46/// One prefetch stage of a [`QueryRequest`]: produces the candidate set its parent re-scores.
47/// Prefetches nest, forming a candidate-resolution tree evaluated leaves-first.
48#[derive(Clone, Debug, PartialEq)]
49pub struct Prefetch {
50 /// Nested sub-prefetches resolved before this one.
51 pub prefetches: Vec<Prefetch>,
52 /// How to score this stage's candidates. `None` scrolls by id instead of scoring.
53 pub query: Option<ScoringQuery>,
54 /// Max number of candidates this stage passes to its parent.
55 pub limit: usize,
56 /// Additional search params.
57 pub params: Option<SearchParams>,
58 /// Look only for points which satisfy these conditions.
59 pub filter: Option<Filter>,
60 /// Exclude candidates with a worse score than this.
61 pub score_threshold: Option<ScoreType>,
62}
63
64impl Prefetch {
65 pub fn new(limit: usize) -> Self {
66 Self {
67 prefetches: Vec::new(),
68 query: None,
69 limit,
70 params: None,
71 filter: None,
72 score_threshold: None,
73 }
74 }
75}