|
16 | 16 | * specific language governing permissions and limitations |
17 | 17 | * under the License. |
18 | 18 | */ |
19 | | -import { FieldCollapse } from '@global/search/_types/FieldCollapse' |
20 | | -import { Rescore } from '@global/search/_types/rescoring' |
21 | | -import { UserDefinedValue } from '@spec_utils/UserDefinedValue' |
22 | 19 | import { QueryVector, QueryVectorBuilder, RescoreVector } from '@_types/Knn' |
23 | 20 | import { float, integer } from '@_types/Numeric' |
24 | 21 | import { Sort, SortResults } from '@_types/sort' |
| 22 | +import { FieldCollapse } from '@global/search/_types/FieldCollapse' |
| 23 | +import { Rescore } from '@global/search/_types/rescoring' |
| 24 | +import { UserDefinedValue } from '@spec_utils/UserDefinedValue' |
25 | 25 | import { Id, IndexName } from './common' |
26 | 26 | import { QueryContainer } from './query_dsl/abstractions' |
27 | 27 |
|
28 | 28 | /** |
29 | 29 | * @variants container |
30 | 30 | */ |
31 | 31 | export class RetrieverContainer { |
32 | | - /** A retriever that replaces the functionality of a traditional query. */ |
33 | | - standard?: StandardRetriever |
34 | | - /** A retriever that replaces the functionality of a knn search. */ |
35 | | - knn?: KnnRetriever |
36 | | - /** A retriever that produces top documents from reciprocal rank fusion (RRF). */ |
37 | | - rrf?: RRFRetriever |
38 | | - /** A retriever that reranks the top documents based on a reranking model using the InferenceAPI */ |
39 | | - text_similarity_reranker?: TextSimilarityReranker |
40 | | - /** A retriever that replaces the functionality of a rule query. */ |
41 | | - rule?: RuleRetriever |
42 | | - /** A retriever that re-scores only the results produced by its child retriever. */ |
43 | | - rescorer?: RescorerRetriever |
44 | | - /** A retriever that supports the combination of different retrievers through a weighted linear combination. */ |
45 | | - linear?: LinearRetriever |
46 | | - /** |
47 | | - * A pinned retriever applies pinned documents to the underlying retriever. |
48 | | - * This retriever will rewrite to a PinnedQueryBuilder. |
49 | | - */ |
50 | | - pinned?: PinnedRetriever |
| 32 | + /** A retriever that replaces the functionality of a traditional query. */ |
| 33 | + standard?: StandardRetriever |
| 34 | + /** A retriever that replaces the functionality of a knn search. */ |
| 35 | + knn?: KnnRetriever |
| 36 | + /** A retriever that produces top documents from reciprocal rank fusion (RRF). */ |
| 37 | + rrf?: RRFRetriever |
| 38 | + /** A retriever that reranks the top documents based on a reranking model using the InferenceAPI */ |
| 39 | + text_similarity_reranker?: TextSimilarityReranker |
| 40 | + /** A retriever that replaces the functionality of a rule query. */ |
| 41 | + rule?: RuleRetriever |
| 42 | + /** A retriever that re-scores only the results produced by its child retriever. */ |
| 43 | + rescorer?: RescorerRetriever |
| 44 | + /** A retriever that supports the combination of different retrievers through a weighted linear combination. */ |
| 45 | + linear?: LinearRetriever |
| 46 | + /** |
| 47 | + * A pinned retriever applies pinned documents to the underlying retriever. |
| 48 | + * This retriever will rewrite to a PinnedQueryBuilder. |
| 49 | + */ |
| 50 | + pinned?: PinnedRetriever |
51 | 51 | } |
52 | 52 |
|
53 | 53 | export class RetrieverBase { |
54 | | - /** Query to filter the documents that can match. */ |
55 | | - filter?: QueryContainer | QueryContainer[] |
56 | | - /** Minimum _score for matching documents. Documents with a lower _score are not included in the top documents. */ |
57 | | - min_score?: float |
58 | | - /** Retriever name. */ |
59 | | - _name?: string |
| 54 | + /** Query to filter the documents that can match. */ |
| 55 | + filter?: QueryContainer | QueryContainer[] |
| 56 | + /** Minimum _score for matching documents. Documents with a lower _score are not included in the top documents. */ |
| 57 | + min_score?: float |
| 58 | + /** Retriever name. */ |
| 59 | + _name?: string |
60 | 60 | } |
61 | 61 |
|
62 | 62 | export class RescorerRetriever extends RetrieverBase { |
63 | | - /** Inner retriever. */ |
64 | | - retriever: RetrieverContainer |
65 | | - rescore: Rescore | Rescore[] |
| 63 | + /** Inner retriever. */ |
| 64 | + retriever: RetrieverContainer |
| 65 | + rescore: Rescore | Rescore[] |
66 | 66 | } |
67 | 67 |
|
68 | 68 | export class LinearRetriever extends RetrieverBase { |
69 | | - /** Inner retrievers. */ |
70 | | - retrievers?: InnerRetriever[] |
71 | | - rank_window_size: integer |
| 69 | + /** Inner retrievers. */ |
| 70 | + retrievers?: InnerRetriever[] |
| 71 | + rank_window_size: integer |
72 | 72 | } |
73 | 73 |
|
74 | 74 | export class PinnedRetriever extends RetrieverBase { |
75 | | - /** Inner retriever. */ |
76 | | - retriever: RetrieverContainer |
77 | | - ids?: string[] |
78 | | - docs?: SpecifiedDocument[] |
79 | | - rank_window_size: integer |
| 75 | + /** Inner retriever. */ |
| 76 | + retriever: RetrieverContainer |
| 77 | + ids?: string[] |
| 78 | + docs?: SpecifiedDocument[] |
| 79 | + rank_window_size: integer |
80 | 80 | } |
81 | 81 |
|
82 | 82 | export class InnerRetriever { |
83 | | - retriever: RetrieverContainer |
84 | | - weight: float |
85 | | - normalizer: ScoreNormalizer |
| 83 | + retriever: RetrieverContainer |
| 84 | + weight: float |
| 85 | + normalizer: ScoreNormalizer |
86 | 86 | } |
87 | 87 |
|
88 | 88 | export enum ScoreNormalizer { |
89 | | - none, |
90 | | - minmax |
| 89 | + none, |
| 90 | + minmax |
91 | 91 | } |
92 | 92 |
|
93 | 93 | export class SpecifiedDocument { |
94 | | - index?: IndexName |
95 | | - id: Id |
| 94 | + index?: IndexName |
| 95 | + id: Id |
96 | 96 | } |
97 | 97 |
|
98 | 98 | export class StandardRetriever extends RetrieverBase { |
99 | | - /** Defines a query to retrieve a set of top documents. */ |
100 | | - query?: QueryContainer |
101 | | - /** Defines a search after object parameter used for pagination. */ |
102 | | - search_after?: SortResults |
103 | | - /** Maximum number of documents to collect for each shard. */ |
104 | | - terminate_after?: integer |
105 | | - /** A sort object that that specifies the order of matching documents. */ |
106 | | - sort?: Sort |
107 | | - /** Collapses the top documents by a specified key into a single top document per key. */ |
108 | | - collapse?: FieldCollapse |
| 99 | + /** Defines a query to retrieve a set of top documents. */ |
| 100 | + query?: QueryContainer |
| 101 | + /** Defines a search after object parameter used for pagination. */ |
| 102 | + search_after?: SortResults |
| 103 | + /** Maximum number of documents to collect for each shard. */ |
| 104 | + terminate_after?: integer |
| 105 | + /** A sort object that that specifies the order of matching documents. */ |
| 106 | + sort?: Sort |
| 107 | + /** Collapses the top documents by a specified key into a single top document per key. */ |
| 108 | + collapse?: FieldCollapse |
109 | 109 | } |
110 | 110 |
|
111 | 111 | export class KnnRetriever extends RetrieverBase { |
112 | | - /** The name of the vector field to search against. */ |
113 | | - field: string |
114 | | - /** Query vector. Must have the same number of dimensions as the vector field you are searching against. You must provide a query_vector_builder or query_vector, but not both. */ |
115 | | - query_vector?: QueryVector |
116 | | - /** Defines a model to build a query vector. */ |
117 | | - query_vector_builder?: QueryVectorBuilder |
118 | | - /** Number of nearest neighbors to return as top hits. */ |
119 | | - k: integer |
120 | | - /** Number of nearest neighbor candidates to consider per shard. */ |
121 | | - num_candidates: integer |
122 | | - /** The minimum similarity required for a document to be considered a match. */ |
123 | | - similarity?: float |
124 | | - /** Apply oversampling and rescoring to quantized vectors |
125 | | - * @availability stack since=8.18.0 |
126 | | - * @availability serverless |
127 | | - */ |
128 | | - rescore_vector?: RescoreVector |
| 112 | + /** The name of the vector field to search against. */ |
| 113 | + field: string |
| 114 | + /** Query vector. Must have the same number of dimensions as the vector field you are searching against. You must provide a query_vector_builder or query_vector, but not both. */ |
| 115 | + query_vector?: QueryVector |
| 116 | + /** Defines a model to build a query vector. */ |
| 117 | + query_vector_builder?: QueryVectorBuilder |
| 118 | + /** Number of nearest neighbors to return as top hits. */ |
| 119 | + k: integer |
| 120 | + /** Number of nearest neighbor candidates to consider per shard. */ |
| 121 | + num_candidates: integer |
| 122 | + /** The minimum similarity required for a document to be considered a match. */ |
| 123 | + similarity?: float |
| 124 | + /** Apply oversampling and rescoring to quantized vectors |
| 125 | + * @availability stack since=8.18.0 |
| 126 | + * @availability serverless |
| 127 | + */ |
| 128 | + rescore_vector?: RescoreVector |
129 | 129 | } |
130 | 130 |
|
131 | 131 | export class RRFRetriever extends RetrieverBase { |
132 | | - /** A list of child retrievers to specify which sets of returned top documents will have the RRF formula applied to them. */ |
133 | | - retrievers: RetrieverContainer[] |
134 | | - /** This value determines how much influence documents in individual result sets per query have over the final ranked result set. */ |
135 | | - rank_constant?: integer |
136 | | - /** This value determines the size of the individual result sets per query. */ |
137 | | - rank_window_size?: integer |
| 132 | + /** A list of child retrievers to specify which sets of returned top documents will have the RRF formula applied to them. */ |
| 133 | + retrievers: RetrieverContainer[] |
| 134 | + /** This value determines how much influence documents in individual result sets per query have over the final ranked result set. */ |
| 135 | + rank_constant?: integer |
| 136 | + /** This value determines the size of the individual result sets per query. */ |
| 137 | + rank_window_size?: integer |
138 | 138 | } |
139 | 139 |
|
140 | 140 | export class TextSimilarityReranker extends RetrieverBase { |
141 | | - /** The nested retriever which will produce the first-level results, that will later be used for reranking. */ |
142 | | - retriever: RetrieverContainer |
143 | | - /** This value determines how many documents we will consider from the nested retriever. */ |
144 | | - rank_window_size?: integer |
145 | | - /** Unique identifier of the inference endpoint created using the inference API. */ |
146 | | - inference_id?: string |
147 | | - /** The text snippet used as the basis for similarity comparison */ |
148 | | - inference_text?: string |
149 | | - /** The document field to be used for text similarity comparisons. This field should contain the text that will be evaluated against the inference_text */ |
150 | | - field?: string |
| 141 | + /** The nested retriever which will produce the first-level results, that will later be used for reranking. */ |
| 142 | + retriever: RetrieverContainer |
| 143 | + /** This value determines how many documents we will consider from the nested retriever. */ |
| 144 | + rank_window_size?: integer |
| 145 | + /** Unique identifier of the inference endpoint created using the inference API. */ |
| 146 | + inference_id?: string |
| 147 | + /** The text snippet used as the basis for similarity comparison */ |
| 148 | + inference_text?: string |
| 149 | + /** The document field to be used for text similarity comparisons. This field should contain the text that will be evaluated against the inference_text */ |
| 150 | + field?: string |
151 | 151 | } |
152 | 152 |
|
153 | 153 | export class RuleRetriever extends RetrieverBase { |
154 | | - /** The ruleset IDs containing the rules this retriever is evaluating against. */ |
155 | | - ruleset_ids: Id | Id[] |
156 | | - /** The match criteria that will determine if a rule in the provided rulesets should be applied. */ |
157 | | - match_criteria: UserDefinedValue |
158 | | - /** The retriever whose results rules should be applied to. */ |
159 | | - retriever: RetrieverContainer |
160 | | - /** This value determines the size of the individual result set. */ |
161 | | - rank_window_size?: integer |
| 154 | + /** The ruleset IDs containing the rules this retriever is evaluating against. */ |
| 155 | + ruleset_ids: Id | Id[] |
| 156 | + /** The match criteria that will determine if a rule in the provided rulesets should be applied. */ |
| 157 | + match_criteria: UserDefinedValue |
| 158 | + /** The retriever whose results rules should be applied to. */ |
| 159 | + retriever: RetrieverContainer |
| 160 | + /** This value determines the size of the individual result set. */ |
| 161 | + rank_window_size?: integer |
162 | 162 | } |
0 commit comments