Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6d4d70

Browse files
authored
Add hybrid/semantic/keyword retrieval modes with reranker config (#23)
# Changes - Add `HybridRetrieval`, `SemanticRetrieval`, and `KeywordRetrieval` messages - Add `RerankerModel` and `ReciprocalRankFusion` reranker configs - Extend `CollectionsSearch` tool with `instructions` and `retrieval_mode` - Deprecate RankingMetric in favor of new retrieval modes
1 parent 3627496 commit f6d4d70

File tree

2 files changed

+88
-5
lines changed

2 files changed

+88
-5
lines changed

proto/xai/api/v1/chat.proto

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package xai_api;
44

55
import "google/protobuf/timestamp.proto";
66
import "xai/api/v1/deferred.proto";
7+
import "xai/api/v1/documents.proto";
78
import "xai/api/v1/image.proto";
89
import "xai/api/v1/sample.proto";
910
import "xai/api/v1/usage.proto";
@@ -665,6 +666,20 @@ message CollectionsSearch {
665666
// Optional number of chunks to be returned for each collections search.
666667
// Defaults to 10.
667668
optional int32 limit = 2;
669+
670+
// User-defined instructions to be included in the search query. Defaults to generic search
671+
// instructions used by the collections search backend if unset.
672+
optional string instructions = 3;
673+
674+
// How to perform the document search. Defaults to hybrid retrieval when unset.
675+
oneof retrieval_mode {
676+
// Perform hybrid retrieval combining keyword and semantic search.
677+
HybridRetrieval hybrid_retrieval = 4;
678+
// Perform pure semantic retrieval using dense embeddings.
679+
SemanticRetrieval semantic_retrieval = 5;
680+
// Perform keyword-based retrieval using sparse embeddings.
681+
KeywordRetrieval keyword_retrieval = 6;
682+
}
668683
}
669684

670685
message AttachmentSearch {

proto/xai/api/v1/documents.proto

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,68 @@ service Documents {
66
rpc Search(SearchRequest) returns (SearchResponse) {}
77
}
88

9+
// Document search using a combination of keyword and semantic search.
10+
message HybridRetrieval {
11+
// Overfetch multiplier applied to the requested search limit.
12+
// When set, fetches (limit * search_multiplier) results from each retrieval method
13+
// before reranking, then returns the top `limit` results after reranking.
14+
// Valid range is [1, 100]. Defaults to 1 when unset.
15+
optional int32 search_multiplier = 1;
16+
17+
// Which reranker to use to limit results to the desired value.
18+
oneof reranker {
19+
// Use a reranker model to perform the reranking.
20+
RerankerModel reranker_model = 2;
21+
// Use RRF to perform the reranking.
22+
ReciprocalRankFusion reciprocal_rank_fusion = 3;
23+
}
24+
}
25+
26+
// Document search using keyword matching (sparse embeddings).
27+
message KeywordRetrieval {
28+
// Optional, but always used when doing search across multiple collections.
29+
optional RerankerModel reranker = 1;
30+
}
31+
32+
// Document search using semantic similarity (dense embeddings).
33+
message SemanticRetrieval {
34+
// Optional, but always used when doing search across multiple collections.
35+
optional RerankerModel reranker = 1;
36+
}
37+
38+
// Configuration for reciprocal rank fusion (RRF) reranking.
39+
message ReciprocalRankFusion {
40+
// The RRF constant k used in the reciprocal rank fusion formula. Defaults to 60.
41+
optional int32 k = 1;
42+
43+
// Weight for embedding (dense) search results. Should be between 0 and 1. Defaults to 0.5.
44+
float embedding_weight = 3;
45+
46+
// Weight for keyword (sparse) search results. Should be between 0 and 1. Defaults to 0.5.
47+
float text_weight = 4;
48+
49+
// Deprecated: Use embedding_weight and text_weight instead.
50+
reserved 2;
51+
}
52+
53+
// Configuration for model-based reranking.
54+
message RerankerModel {
55+
// The model to use for reranking. Defaults to standard reranker model.
56+
optional string model = 1;
57+
58+
// Instructions for the reranking model. Defaults to generic reranking instructions.
59+
optional string instructions = 2;
60+
}
61+
962
// RankingMetric is the metric to use for the search.
63+
// Deprecated: Metric now comes from what is set in the collection creation.
1064
enum RankingMetric {
1165
RANKING_METRIC_UNKNOWN = 0;
1266
RANKING_METRIC_L2_DISTANCE = 1;
1367
RANKING_METRIC_COSINE_SIMILARITY = 2;
1468
}
1569

70+
// Message that contains settings needed to do a document search.
1671
message SearchRequest {
1772
// The query to search for which will be embedded using the
1873
// same embedding model as the one used for the source to query.
@@ -21,14 +76,27 @@ message SearchRequest {
2176
DocumentsSource source = 2;
2277
// The number of chunks to return.
2378
// Will always return the top matching chunks.
24-
// Optional, defaults to 10
79+
// Optional, defaults to 10.
2580
optional int32 limit = 3;
26-
27-
// The ranking metric to use for the search. Defaults to RANK_METRIC_L2_DISTANCE.
28-
optional RankingMetric ranking_metric = 4;
29-
3081
// User-defined instructions to be included in the search query. Defaults to generic search instructions.
3182
optional string instructions = 5;
83+
84+
// How to perform the document search. Defaults to HybridRetrieval
85+
oneof retrieval_mode {
86+
HybridRetrieval hybrid_retrieval = 11;
87+
SemanticRetrieval semantic_retrieval = 12;
88+
KeywordRetrieval keyword_retrieval = 13;
89+
}
90+
91+
// Deprecated: Metric now comes from what is set during collection creation.
92+
optional RankingMetric ranking_metric = 4 [deprecated = true];
93+
94+
// Deprecated: Use retrieval_mode instead
95+
reserved 6;
96+
reserved 7;
97+
reserved 8;
98+
reserved 9;
99+
reserved 10;
32100
}
33101

34102
// SearchResponse message contains the results of a document search operation.

0 commit comments

Comments
 (0)