Commit 5453aab
authored
[Bug] query_namespaces can handle single result (#421)
## Problem
In order to merge results across multiple queries, the SDK must know
which similarity metric an index is using. For dotproduct and cosine
indexes, a larger score is better while for euclidean a smaller score is
better. Unfortunately the data plane API does not currently expose the
metric type and a separate call to the control plane to find out seems
undesirable from a resiliency and performance perspective.
As a workaround, in the initial implementation of `query_namespaces` the
SDK would infer the similarity metric needed to merge results by seeing
whether the scores of query results were ascending or descending. This
worked well, but imposes an implicit limitation that there must be at
least 2 results returned.
We initially believed this would not be a problem but have since learned
that applications using filtering can sometimes filter out all or most
results. So an approach that has the user explicitly telling the SDK
what similarity metric is being used is preferred to handle these edge
cases with 1 or 0 results.
## Solution
- Add a required kwarg to `query_namespaces` to specify the index
similarity metric.
- Modify `QueryResultsAggregator` to use this similarity metric, and
strip out code that was involved in inferring whether results were
ascending or descending.
- Adjust integration tests to pass new metric kwarg. Except for adding
the new kwarg, query_namespaces integration tests did not need to change
which indicates the underlying behavior is still working as before.
## Type of Change
- [x] Bug fix (non-breaking change which fixes an issue)1 parent ec9afe1 commit 5453aab
File tree
5 files changed
+208
-182
lines changed- pinecone
- data
- grpc
- tests
- integration/data
- unit
5 files changed
+208
-182
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
511 | 511 | | |
512 | 512 | | |
513 | 513 | | |
| 514 | + | |
514 | 515 | | |
515 | 516 | | |
516 | 517 | | |
| |||
540 | 541 | | |
541 | 542 | | |
542 | 543 | | |
| 544 | + | |
543 | 545 | | |
544 | 546 | | |
545 | 547 | | |
| |||
554 | 556 | | |
555 | 557 | | |
556 | 558 | | |
| 559 | + | |
557 | 560 | | |
558 | 561 | | |
559 | 562 | | |
| |||
568 | 571 | | |
569 | 572 | | |
570 | 573 | | |
571 | | - | |
| 574 | + | |
572 | 575 | | |
573 | 576 | | |
574 | 577 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | 91 | | |
99 | 92 | | |
100 | | - | |
101 | | - | |
102 | | - | |
| 93 | + | |
103 | 94 | | |
104 | 95 | | |
105 | 96 | | |
106 | | - | |
107 | | - | |
| 97 | + | |
| 98 | + | |
108 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
113 | | - | |
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
128 | 120 | | |
129 | 121 | | |
130 | | - | |
| 122 | + | |
131 | 123 | | |
132 | 124 | | |
133 | 125 | | |
| |||
137 | 129 | | |
138 | 130 | | |
139 | 131 | | |
140 | | - | |
| 132 | + | |
141 | 133 | | |
142 | 134 | | |
143 | | - | |
| 135 | + | |
144 | 136 | | |
145 | 137 | | |
146 | 138 | | |
| |||
162 | 154 | | |
163 | 155 | | |
164 | 156 | | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
| 157 | + | |
| 158 | + | |
175 | 159 | | |
176 | | - | |
| 160 | + | |
177 | 161 | | |
178 | 162 | | |
179 | 163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
409 | 409 | | |
410 | 410 | | |
411 | 411 | | |
| 412 | + | |
412 | 413 | | |
413 | 414 | | |
414 | 415 | | |
| |||
422 | 423 | | |
423 | 424 | | |
424 | 425 | | |
425 | | - | |
| 426 | + | |
426 | 427 | | |
427 | 428 | | |
428 | 429 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | 3 | | |
8 | 4 | | |
9 | 5 | | |
10 | 6 | | |
11 | 7 | | |
12 | | - | |
| 8 | + | |
13 | 9 | | |
14 | 10 | | |
15 | 11 | | |
| |||
50 | 46 | | |
51 | 47 | | |
52 | 48 | | |
| 49 | + | |
53 | 50 | | |
54 | 51 | | |
55 | 52 | | |
| |||
84 | 81 | | |
85 | 82 | | |
86 | 83 | | |
| 84 | + | |
87 | 85 | | |
88 | 86 | | |
89 | 87 | | |
| |||
98 | 96 | | |
99 | 97 | | |
100 | 98 | | |
| 99 | + | |
101 | 100 | | |
102 | 101 | | |
103 | 102 | | |
| |||
110 | 109 | | |
111 | 110 | | |
112 | 111 | | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| 125 | + | |
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
| |||
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
| 141 | + | |
140 | 142 | | |
141 | 143 | | |
142 | 144 | | |
| |||
145 | 147 | | |
146 | 148 | | |
147 | 149 | | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
| 150 | + | |
164 | 151 | | |
165 | 152 | | |
166 | 153 | | |
| |||
183 | 170 | | |
184 | 171 | | |
185 | 172 | | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
199 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
200 | 187 | | |
201 | 188 | | |
202 | 189 | | |
203 | 190 | | |
204 | 191 | | |
205 | 192 | | |
| 193 | + | |
206 | 194 | | |
207 | 195 | | |
208 | 196 | | |
| |||
214 | 202 | | |
215 | 203 | | |
216 | 204 | | |
| 205 | + | |
217 | 206 | | |
218 | 207 | | |
219 | 208 | | |
220 | 209 | | |
221 | 210 | | |
222 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
0 commit comments