Skip to content

Commit 9976d61

Browse files
committed
update proto, generated types, and add new builders
1 parent ab0677f commit 9976d61

File tree

12 files changed

+755
-196
lines changed

12 files changed

+755
-196
lines changed

proto/collections.proto

Lines changed: 134 additions & 95 deletions
Large diffs are not rendered by default.

proto/points.proto

Lines changed: 73 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ enum RecommendStrategy {
425425
// examples, its score is then chosen from the `max(max_pos_score, max_neg_score)`.
426426
// If the `max_neg_score` is chosen then it is squared and negated.
427427
BestScore = 1;
428-
428+
429429
// Uses custom search objective. Compares against all inputs, sums all the scores.
430430
// Scores against positive vectors are added, against negatives are subtracted.
431431
SumScores = 2;
@@ -631,13 +631,40 @@ message PowExpression {
631631

632632
message DecayParamsExpression {
633633
// The variable to decay
634-
Expression x = 1;
634+
Expression x = 1;
635635
// The target value to start decaying from. Defaults to 0.
636-
optional Expression target = 2;
636+
optional Expression target = 2;
637637
// The scale factor of the decay, in terms of `x`. Defaults to 1.0. Must be a non-zero positive number.
638-
optional float scale = 3;
638+
optional float scale = 3;
639639
// The midpoint of the decay. Defaults to 0.5. Output will be this value when `|x - target| == scale`.
640-
optional float midpoint = 4;
640+
optional float midpoint = 4;
641+
}
642+
643+
message NearestInputWithMmr {
644+
// The vector to search for nearest neighbors.
645+
VectorInput nearest = 1;
646+
647+
// Perform MMR (Maximal Marginal Relevance) reranking after search,
648+
// using the same vector in this query to calculate relevance.
649+
Mmr mmr = 2;
650+
}
651+
652+
// Maximal Marginal Relevance (MMR) algorithm for re-ranking the points.
653+
message Mmr {
654+
// Tunable parameter for the MMR algorithm.
655+
// Determines the balance between diversity and relevance.
656+
//
657+
// A higher value favors diversity (dissimilarity to selected results),
658+
// while a lower value favors relevance (similarity to the query vector).
659+
//
660+
// Must be in the range [0, 1].
661+
// Default value is 0.5.
662+
optional float diversity = 2;
663+
664+
// The maximum number of candidates to consider for re-ranking.
665+
//
666+
// If not specified, the `limit` value is used.
667+
optional uint32 candidates_limit = 3;
641668
}
642669

643670
message Query {
@@ -650,6 +677,7 @@ message Query {
650677
Fusion fusion = 6; // Fuse the results of multiple prefetches.
651678
Sample sample = 7; // Sample points from the collection.
652679
Formula formula = 8; // Score boosting via an arbitrary formula
680+
NearestInputWithMmr nearest_with_mmr = 9; // Search nearest neighbors, but re-rank based on the Maximal Marginal Relevance algorithm.
653681
}
654682
}
655683

@@ -830,7 +858,7 @@ message UpdateBatchPoints {
830858
message PointsOperationResponse {
831859
UpdateResult result = 1;
832860
double time = 2; // Time spent to process
833-
optional HardwareUsage usage = 3;
861+
optional Usage usage = 3;
834862
}
835863

836864
message UpdateResult {
@@ -887,25 +915,25 @@ message GroupsResult {
887915
message SearchResponse {
888916
repeated ScoredPoint result = 1;
889917
double time = 2; // Time spent to process
890-
optional HardwareUsage usage = 3;
918+
optional Usage usage = 3;
891919
}
892920

893921
message QueryResponse {
894922
repeated ScoredPoint result = 1;
895923
double time = 2; // Time spent to process
896-
optional HardwareUsage usage = 3;
924+
optional Usage usage = 3;
897925
}
898926

899927
message QueryBatchResponse {
900928
repeated BatchResult result = 1;
901929
double time = 2; // Time spent to process
902-
optional HardwareUsage usage = 3;
930+
optional Usage usage = 3;
903931
}
904932

905933
message QueryGroupsResponse {
906934
GroupsResult result = 1;
907935
double time = 2; // Time spent to process
908-
optional HardwareUsage usage = 3;
936+
optional Usage usage = 3;
909937
}
910938

911939
message BatchResult {
@@ -915,26 +943,26 @@ message BatchResult {
915943
message SearchBatchResponse {
916944
repeated BatchResult result = 1;
917945
double time = 2; // Time spent to process
918-
optional HardwareUsage usage = 3;
946+
optional Usage usage = 3;
919947
}
920948

921949
message SearchGroupsResponse {
922950
GroupsResult result = 1;
923951
double time = 2; // Time spent to process
924-
optional HardwareUsage usage = 3;
952+
optional Usage usage = 3;
925953
}
926954

927955
message CountResponse {
928956
CountResult result = 1;
929957
double time = 2; // Time spent to process
930-
optional HardwareUsage usage = 3;
958+
optional Usage usage = 3;
931959
}
932960

933961
message ScrollResponse {
934962
optional PointId next_page_offset = 1; // Use this offset for the next query
935963
repeated RetrievedPoint result = 2;
936964
double time = 3; // Time spent to process
937-
optional HardwareUsage usage = 4;
965+
optional Usage usage = 4;
938966
}
939967

940968
message CountResult {
@@ -953,42 +981,43 @@ message RetrievedPoint {
953981
message GetResponse {
954982
repeated RetrievedPoint result = 1;
955983
double time = 2; // Time spent to process
956-
optional HardwareUsage usage = 3;
984+
optional Usage usage = 3;
957985
}
958986

959987
message RecommendResponse {
960988
repeated ScoredPoint result = 1;
961989
double time = 2; // Time spent to process
962-
optional HardwareUsage usage = 3;
990+
optional Usage usage = 3;
963991
}
964992

965993
message RecommendBatchResponse {
966994
repeated BatchResult result = 1;
967995
double time = 2; // Time spent to process
968-
optional HardwareUsage usage = 3;
996+
optional Usage usage = 3;
969997
}
970998

971999
message DiscoverResponse {
9721000
repeated ScoredPoint result = 1;
9731001
double time = 2; // Time spent to process
974-
optional HardwareUsage usage = 3;
1002+
optional Usage usage = 3;
9751003
}
9761004

9771005
message DiscoverBatchResponse {
9781006
repeated BatchResult result = 1;
9791007
double time = 2; // Time spent to process
980-
optional HardwareUsage usage = 3;
1008+
optional Usage usage = 3;
9811009
}
9821010

9831011
message RecommendGroupsResponse {
9841012
GroupsResult result = 1;
9851013
double time = 2; // Time spent to process
986-
optional HardwareUsage usage = 3;
1014+
optional Usage usage = 3;
9871015
}
9881016

9891017
message UpdateBatchResponse {
9901018
repeated UpdateResult result = 1;
9911019
double time = 2; // Time spent to process
1020+
optional Usage usage = 3;
9921021
}
9931022

9941023
message FacetResponse {
@@ -999,13 +1028,13 @@ message FacetResponse {
9991028
message SearchMatrixPairsResponse {
10001029
SearchMatrixPairs result = 1;
10011030
double time = 2; // Time spent to process
1002-
optional HardwareUsage usage = 3;
1031+
optional Usage usage = 3;
10031032
}
10041033

10051034
message SearchMatrixOffsetsResponse {
10061035
SearchMatrixOffsets result = 1;
10071036
double time = 2; // Time spent to process
1008-
optional HardwareUsage usage = 3;
1037+
optional Usage usage = 3;
10091038
}
10101039

10111040
// ---------------------------------------------
@@ -1080,6 +1109,7 @@ message Match {
10801109
RepeatedIntegers integers = 6; // Match multiple integers
10811110
RepeatedIntegers except_integers = 7; // Match any other value except those integers
10821111
RepeatedStrings except_keywords = 8; // Match any other value except those keywords
1112+
string phrase = 9; // Match phrase text
10831113
}
10841114
}
10851115

@@ -1166,6 +1196,27 @@ message GeoPoint {
11661196
double lat = 2;
11671197
}
11681198

1199+
// ---------------------------------------------
1200+
// ----------- Measurements collector ----------
1201+
// ---------------------------------------------
1202+
message Usage {
1203+
optional HardwareUsage hardware = 1;
1204+
optional InferenceUsage inference = 2;
1205+
}
1206+
1207+
1208+
// ---------------------------------------------
1209+
// ------------ Inference measurements ----------
1210+
// ---------------------------------------------
1211+
1212+
message InferenceUsage {
1213+
map<string, ModelUsage> models = 1;
1214+
}
1215+
1216+
message ModelUsage {
1217+
uint64 tokens = 1;
1218+
}
1219+
11691220
// ---------------------------------------------
11701221
// ------------ Hardware measurements ----------
11711222
// ---------------------------------------------

src/builders/binary_quantization_builder.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,47 @@ use crate::qdrant::*;
44
pub struct BinaryQuantizationBuilder {
55
/// If true - quantized vectors always will be stored in RAM, ignoring the config of main storage
66
pub(crate) always_ram: Option<Option<bool>>,
7+
pub(crate) encoding: Option<Option<i32>>,
8+
pub(crate) query_encoding: Option<Option<BinaryQuantizationQueryEncoding>>,
79
}
810

911
impl BinaryQuantizationBuilder {
1012
/// If true - quantized vectors always will be stored in RAM, ignoring the config of main storage
11-
#[allow(unused_mut)]
1213
pub fn always_ram(self, value: bool) -> Self {
1314
let mut new = self;
14-
new.always_ram = Option::Some(Option::Some(value));
15+
new.always_ram = Some(Some(value));
16+
new
17+
}
18+
19+
/// Binary quantization encoding method
20+
pub fn encoding(self, value: impl Into<BinaryQuantizationEncoding>) -> Self {
21+
let mut new = self;
22+
let encoding: BinaryQuantizationEncoding = value.into();
23+
new.encoding = Some(Some(encoding.into()));
24+
new
25+
}
26+
27+
/// Asymmetric quantization configuration allows a query to have different quantization than stored vectors.
28+
/// It can increase the accuracy of search at the cost of performance.
29+
pub fn query_encoding(self, value: impl Into<BinaryQuantizationQueryEncoding>) -> Self {
30+
let mut new = self;
31+
new.query_encoding = Some(Some(value.into()));
1532
new
1633
}
1734

1835
fn build_inner(self) -> Result<BinaryQuantization, BinaryQuantizationBuilderError> {
1936
Ok(BinaryQuantization {
2037
always_ram: self.always_ram.unwrap_or_default(),
38+
encoding: self.encoding.unwrap_or_default(),
39+
query_encoding: self.query_encoding.unwrap_or_default(),
2140
})
2241
}
2342
/// Create an empty builder, with all fields set to `None` or `PhantomData`.
2443
fn create_empty() -> Self {
2544
Self {
26-
always_ram: core::default::Default::default(),
45+
always_ram: Default::default(),
46+
encoding: Default::default(),
47+
query_encoding: Default::default(),
2748
}
2849
}
2950
}
@@ -57,8 +78,6 @@ impl BinaryQuantizationBuilder {
5778
}
5879
}
5980

60-
// src/builders/binary_quantization_builder.rs
61-
6281
#[non_exhaustive]
6382
#[derive(Debug)]
6483
pub enum BinaryQuantizationBuilderError {
@@ -96,3 +115,11 @@ impl From<String> for BinaryQuantizationBuilderError {
96115
Self::ValidationError(error)
97116
}
98117
}
118+
119+
impl BinaryQuantizationQueryEncoding {
120+
pub fn new_setting(setting: binary_quantization_query_encoding::Setting) -> Self {
121+
Self {
122+
variant: Some(binary_quantization_query_encoding::Variant::Setting(setting.into())),
123+
}
124+
}
125+
}

0 commit comments

Comments
 (0)