Skip to content

Commit

Permalink
update proto
Browse files Browse the repository at this point in the history
  • Loading branch information
generall committed Jun 19, 2024
1 parent eadaff2 commit db28168
Show file tree
Hide file tree
Showing 6 changed files with 1,972 additions and 741 deletions.
24 changes: 23 additions & 1 deletion proto/collections.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum Datatype {
Default = 0;
Float32 = 1;
Uint8 = 2;
Float16 = 3;
}

message VectorParams {
Expand All @@ -15,6 +16,7 @@ message VectorParams {
optional QuantizationConfig quantization_config = 4; // Configuration of vector quantization config. If omitted - the collection configuration will be used
optional bool on_disk = 5; // If true - serve vectors from disk. If set to false, the vectors will be loaded in RAM.
optional Datatype datatype = 6; // Data type of the vectors
optional MultiVectorConfig multivector_config = 7; // Configuration for multi-vector search
}

message VectorParamsDiff {
Expand Down Expand Up @@ -59,6 +61,15 @@ message SparseVectorConfig {
map<string, SparseVectorParams> map = 1;
}

enum MultiVectorComparator {
MaxSim = 0;
}

message MultiVectorConfig {
MultiVectorComparator comparator = 1; // Comparator for multi-vector search
}


message GetCollectionInfoRequest {
string collection_name = 1; // Name of the collection
}
Expand Down Expand Up @@ -181,6 +192,10 @@ message SparseIndexConfig {
Store inverted index on disk. If set to false, the index will be stored in RAM.
*/
optional bool on_disk = 2;
/*
Datatype used to store weights in the index.
*/
optional Datatype datatype = 3;
}

message WalConfigDiff {
Expand Down Expand Up @@ -464,6 +479,7 @@ enum ReplicaState {
Listener = 4; // A shard which receives data, but is not used for search; Useful for backup shards
PartialSnapshot = 5; // Deprecated: snapshot shard transfer is in progress; Updates should not be sent to (and are ignored by) the shard
Recovery = 6; // Shard is undergoing recovered by an external node; Normally rejects updates, accepts updates if force is true
Resharding = 7; // Points are being migrated to this shard as part of resharding
}

message ShardKey {
Expand All @@ -489,13 +505,14 @@ message RemoteShardInfo {

message ShardTransferInfo {
uint32 shard_id = 1; // Local shard id
optional uint32 to_shard_id = 5;
uint64 from = 2;
uint64 to = 3;
bool sync = 4; // If `true` transfer is a synchronization of a replicas; If `false` transfer is a moving of a shard from one peer to another
}

message CollectionClusterInfoResponse {
uint64 peer_id = 1; // ID of this peer
uint64 peer_id = 1; // ID of this peer
uint64 shard_count = 2; // Total number of shards
repeated LocalShardInfo local_shards = 3; // Local shards
repeated RemoteShardInfo remote_shards = 4; // Remote shards
Expand All @@ -504,26 +521,30 @@ message CollectionClusterInfoResponse {

message MoveShard {
uint32 shard_id = 1; // Local shard id
optional uint32 to_shard_id = 5;
uint64 from_peer_id = 2;
uint64 to_peer_id = 3;
optional ShardTransferMethod method = 4;
}

message ReplicateShard {
uint32 shard_id = 1; // Local shard id
optional uint32 to_shard_id = 5;
uint64 from_peer_id = 2;
uint64 to_peer_id = 3;
optional ShardTransferMethod method = 4;
}

message AbortShardTransfer {
uint32 shard_id = 1; // Local shard id
optional uint32 to_shard_id = 4;
uint64 from_peer_id = 2;
uint64 to_peer_id = 3;
}

message RestartTransfer {
uint32 shard_id = 1; // Local shard id
optional uint32 to_shard_id = 5;
uint64 from_peer_id = 2;
uint64 to_peer_id = 3;
ShardTransferMethod method = 4;
Expand All @@ -533,6 +554,7 @@ enum ShardTransferMethod {
StreamRecords = 0; // Stream shard records in batches
Snapshot = 1; // Snapshot the shard and recover it on the target peer
WalDelta = 2; // Resolve WAL delta between peers and transfer the difference
ReshardingStreamRecords = 3; // Stream shard records in batches for resharding
}

message Replica {
Expand Down
106 changes: 104 additions & 2 deletions proto/points.proto
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,34 @@ message SparseIndices {
repeated uint32 data = 1;
}

// Legacy vector format, which determines the vector type by the configuration of its fields.
message Vector {
repeated float data = 1; // Vector data (flatten for multi vectors)
optional SparseIndices indices = 2; // Sparse indices for sparse vectors
optional uint32 vectors_count = 3; // Number of vectors per multi vector
}

message DenseVector {
repeated float data = 1;
optional SparseIndices indices = 2;
}

message SparseVector {
repeated float values = 1;
repeated uint32 indices = 2;
}

message MultiDenseVector {
repeated DenseVector vectors = 1;
}

// Vector type to be used in queries. Ids will be substituted with their corresponding vectors from the collection.
message VectorInput {
oneof variant {
PointId id = 1;
DenseVector dense = 2;
SparseVector sparse = 3;
MultiDenseVector multi_dense = 4;
}
}

// ---------------------------------------------
Expand Down Expand Up @@ -450,13 +475,77 @@ message DiscoverBatchPoints {
}

message CountPoints {
string collection_name = 1; // name of the collection
string collection_name = 1; // Name of the collection
Filter filter = 2; // Filter conditions - return only those points that satisfy the specified conditions
optional bool exact = 3; // If `true` - return exact count, if `false` - return approximate count
optional ReadConsistency read_consistency = 4; // Options for specifying read consistency guarantees
optional ShardKeySelector shard_key_selector = 5; // Specify in which shards to look for the points, if not specified - look in all shards
}

message RecommendInput {
repeated VectorInput positive = 1; // Look for vectors closest to the vectors from these points
repeated VectorInput negative = 2; // Try to avoid vectors like the vector from these points
optional RecommendStrategy strategy = 3; // How to use the provided vectors to find the results
}

message ContextInputPair {
VectorInput positive = 1; // A positive vector
VectorInput negative = 2; // Repel from this vector
}

message DiscoverInput {
VectorInput target = 1; // Use this as the primary search objective
ContextInput context = 2; // Search space will be constrained by these pairs of vectors
}

message ContextInput {
repeated ContextInputPair pairs = 1; // Search space will be constrained by these pairs of vectors
}

enum Fusion {
RRF = 0; // Reciprocal Rank Fusion
}

message Query {
oneof variant {
VectorInput nearest = 1; // Find the nearest neighbors to this vector.
RecommendInput recommend = 2; // Use multiple positive and negative vectors to find the results.
DiscoverInput discover = 3; // Search for nearest points, but constrain the search space with context
ContextInput context = 4; // Return points that live in positive areas.
OrderBy order_by = 5; // Order the points by a payload field.
Fusion fusion = 6; // Fuse the results of multiple prefetches.
}
}

message PrefetchQuery {
repeated PrefetchQuery prefetch = 1; // Sub-requests to perform first. If present, the query will be performed on the results of the prefetches.
optional Query query = 2; // Query to perform. If missing, returns points ordered by their IDs.
optional string using = 3; // Define which vector to use for querying. If missing, the default vector is is used.
optional Filter filter = 4; // Filter conditions - return only those points that satisfy the specified conditions.
optional SearchParams search_params = 5; // Search params for when there is no prefetch.
optional float score_threshold = 6; // Return points with scores better than this threshold.
optional uint64 limit = 7; // Max number of points. Default is 10
optional LookupLocation lookup_from = 8; // The location to use for IDs lookup, if not specified - use the current collection and the 'using' vector
}

message QueryPoints {
string collection_name = 1; // Name of the collection
repeated PrefetchQuery prefetch = 2; // Sub-requests to perform first. If present, the query will be performed on the results of the prefetches.
optional Query query = 3; // Query to perform. If missing, returns points ordered by their IDs.
optional string using = 4; // Define which vector to use for querying. If missing, the default vector is used.
optional Filter filter = 5; // Filter conditions - return only those points that satisfy the specified conditions.
optional SearchParams search_params = 6; // Search params for when there is no prefetch.
optional float score_threshold = 7; // Return points with scores better than this threshold.
optional uint64 limit = 8; // Max number of points. Default is 10.
optional uint64 offset = 9; // Offset of the result. Skip this many points. Default is 0.
optional WithVectorsSelector with_vectors = 10; // Options for specifying which vectors to include into the response.
optional WithPayloadSelector with_payload = 11; // Options for specifying which payload to include or not.
optional ReadConsistency read_consistency = 12; // Options for specifying read consistency guarantees.
optional ShardKeySelector shard_key_selector = 13; // Specify in which shards to look for the points, if not specified - look in all shards.
optional LookupLocation lookup_from = 14; // The location to use for IDs lookup, if not specified - use the current collection and the 'using' vector
optional uint64 timeout = 15; // If set, overrides global timeout setting for this request. Unit is seconds.
}

message PointsUpdateOperation {
message PointStructList {
repeated PointStruct points = 1;
Expand Down Expand Up @@ -539,6 +628,13 @@ enum UpdateStatus {
ClockRejected = 3; // Internal: update is rejected due to an outdated clock
}

message OrderValue {
oneof variant {
int64 int = 1;
double float = 2;
}
}

message ScoredPoint {
PointId id = 1; // Point id
map<string, Value> payload = 2; // Payload
Expand All @@ -547,6 +643,7 @@ message ScoredPoint {
uint64 version = 5; // Last update operation applied to this point
optional Vectors vectors = 6; // Vectors to search
optional ShardKey shard_key = 7; // Shard key
optional OrderValue order_value = 8; // Order by value
}

message GroupId {
Expand Down Expand Up @@ -575,6 +672,11 @@ message SearchResponse {
double time = 2; // Time spent to process
}

message QueryResponse {
repeated ScoredPoint result = 1;
double time = 2; // Time spent to process
}

message BatchResult {
repeated ScoredPoint result = 1;
}
Expand Down
4 changes: 4 additions & 0 deletions proto/points_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,8 @@ service Points {
Perform multiple update operations in one request
*/
rpc UpdateBatch (UpdateBatchPoints) returns (UpdateBatchResponse) {}
/*
Universally query points. This endpoint covers all capabilities of search, recommend, discover, filters. But also enables hybrid and multi-stage queries.
*/
rpc Query (QueryPoints) returns (QueryResponse) {}
}
49 changes: 33 additions & 16 deletions src/grpc_conversions/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@ use crate::prelude::point_id::PointIdOptions;
use crate::prelude::{DeleteCollection, Value};
use crate::qdrant::value::Kind;
use crate::qdrant::vectors::VectorsOptions;
use crate::qdrant::{
shard_key, with_payload_selector, with_vectors_selector, CollectionClusterInfoRequest,
CollectionExistsRequest, CreateSnapshotRequest, DeleteAlias, DeleteCollectionBuilder,
DeleteFullSnapshotRequest, GetCollectionInfoRequest, IsEmptyCondition, IsNullCondition,
ListCollectionAliasesRequest, ListSnapshotsRequest, NamedVectors, PayloadExcludeSelector,
PayloadIncludeSelector, PointId, RepeatedIntegers, RepeatedStrings, ShardKeySelector,
SparseIndices, SparseVectorConfig, SparseVectorParams, Struct, Vector, VectorParams,
VectorParamsDiff, VectorParamsDiffMap, VectorParamsMap, Vectors, VectorsSelector,
WithPayloadSelector, WithVectorsSelector,
};
use crate::qdrant::{shard_key, with_payload_selector, with_vectors_selector, CollectionClusterInfoRequest, CollectionExistsRequest, CreateSnapshotRequest, DeleteAlias, DeleteCollectionBuilder, DeleteFullSnapshotRequest, GetCollectionInfoRequest, IsEmptyCondition, IsNullCondition, ListCollectionAliasesRequest, ListSnapshotsRequest, NamedVectors, PayloadExcludeSelector, PayloadIncludeSelector, PointId, RepeatedIntegers, RepeatedStrings, ShardKeySelector, SparseIndices, SparseVectorConfig, SparseVectorParams, Struct, Vector, VectorParams, VectorParamsDiff, VectorParamsDiffMap, VectorParamsMap, Vectors, VectorsSelector, WithPayloadSelector, WithVectorsSelector, ShardKey};
use std::collections::HashMap;

impl From<bool> for WithPayloadSelector {
Expand Down Expand Up @@ -39,6 +30,7 @@ impl From<Vec<f32>> for Vector {
Vector {
data: vector,
indices: None,
vectors_count: None,
}
}
}
Expand All @@ -61,6 +53,7 @@ impl From<&[(u32, f32)]> for Vector {
Vector {
data: values,
indices: Some(SparseIndices { data: indices }),
vectors_count: None,
}
}
}
Expand Down Expand Up @@ -192,8 +185,8 @@ impl From<&str> for Value {
}

impl<T> From<Vec<(&str, T)>> for Value
where
T: Into<Value>,
where
T: Into<Value>,
{
fn from(val: Vec<(&str, T)>) -> Self {
Self {
Expand All @@ -219,27 +212,51 @@ impl From<u64> for shard_key::Key {
}
}

impl From<String> for ShardKey {
fn from(keyword: String) -> Self {
ShardKey {
key: Some(shard_key::Key::Keyword(keyword)),
}
}
}

impl From<u64> for ShardKey {
fn from(number: u64) -> Self {
ShardKey {
key: Some(shard_key::Key::Number(number)),
}
}
}

impl From<String> for ShardKeySelector {
fn from(keyword: String) -> Self {
keyword.into()
ShardKeySelector {
shard_keys: vec![ShardKey::from(keyword)],
}
}
}

impl From<u64> for ShardKeySelector {
fn from(number: u64) -> Self {
number.into()
ShardKeySelector {
shard_keys: vec![ShardKey::from(number)],
}
}
}

impl From<Vec<String>> for ShardKeySelector {
fn from(keywords: Vec<String>) -> Self {
keywords.into()
ShardKeySelector {
shard_keys: keywords.into_iter().map(ShardKey::from).collect(),
}
}
}

impl From<Vec<u64>> for ShardKeySelector {
fn from(numbers: Vec<u64>) -> Self {
numbers.into()
ShardKeySelector {
shard_keys: numbers.into_iter().map(ShardKey::from).collect(),
}
}
}

Expand Down
Loading

0 comments on commit db28168

Please sign in to comment.