Commit 782b46e
.Net: Implementing cosine similarity in duckdb engine (#2638)
### Motivation and Context
<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
1. Why is this change required?
2. What problem does it solve?
3. What scenario does it contribute to?
4. If it fixes an open issue, please link to the issue here.
-->
This pr moves cosine similarity calculation into duckDb engine to
improve performance and memory usage.
### Description
Moving cosine similarity calculation on the server there is no need to
marshal out more data than the one scoring enough and meeting the result
limit.
<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->
- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
---------
Co-authored-by: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com>1 parent f6fb9f9 commit 782b46e
File tree
5 files changed
+77
-76
lines changed- dotnet
- src/Connectors
- Connectors.Memory.DuckDB
- Connectors.UnitTests/Memory/DuckDB
5 files changed
+77
-76
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
| 226 | + | |
226 | 227 | | |
227 | 228 | | |
228 | 229 | | |
| |||
Lines changed: 55 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| 23 | + | |
| 24 | + | |
21 | 25 | | |
22 | 26 | | |
23 | 27 | | |
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
27 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
28 | 42 | | |
29 | 43 | | |
30 | 44 | | |
| |||
34 | 48 | | |
35 | 49 | | |
36 | 50 | | |
37 | | - | |
| 51 | + | |
38 | 52 | | |
39 | 53 | | |
40 | 54 | | |
| |||
50 | 64 | | |
51 | 65 | | |
52 | 66 | | |
53 | | - | |
| 67 | + | |
54 | 68 | | |
55 | 69 | | |
56 | 70 | | |
57 | 71 | | |
58 | | - | |
59 | 72 | | |
60 | 73 | | |
61 | 74 | | |
62 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
63 | 83 | | |
64 | | - | |
| 84 | + | |
65 | 85 | | |
| 86 | + | |
| 87 | + | |
66 | 88 | | |
67 | | - | |
68 | | - | |
69 | | - | |
| 89 | + | |
70 | 90 | | |
71 | 91 | | |
72 | 92 | | |
73 | | - | |
74 | 93 | | |
75 | 94 | | |
76 | 95 | | |
| |||
98 | 117 | | |
99 | 118 | | |
100 | 119 | | |
101 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
102 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
103 | 127 | | |
104 | 128 | | |
| 129 | + | |
| 130 | + | |
105 | 131 | | |
106 | 132 | | |
107 | | - | |
108 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
109 | 137 | | |
110 | 138 | | |
111 | 139 | | |
| |||
116 | 144 | | |
117 | 145 | | |
118 | 146 | | |
| 147 | + | |
119 | 148 | | |
120 | | - | |
| 149 | + | |
121 | 150 | | |
122 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
123 | 160 | | |
124 | 161 | | |
125 | 162 | | |
| |||
130 | 167 | | |
131 | 168 | | |
132 | 169 | | |
133 | | - | |
| 170 | + | |
134 | 171 | | |
135 | 172 | | |
136 | 173 | | |
| |||
140 | 177 | | |
141 | 178 | | |
142 | 179 | | |
143 | | - | |
| 180 | + | |
144 | 181 | | |
145 | | - | |
| 182 | + | |
146 | 183 | | |
147 | 184 | | |
148 | 185 | | |
149 | | - | |
| 186 | + | |
150 | 187 | | |
151 | 188 | | |
152 | 189 | | |
| |||
175 | 212 | | |
176 | 213 | | |
177 | 214 | | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | 215 | | |
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
14 | 20 | | |
Lines changed: 14 additions & 46 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
24 | | - | |
| 23 | + | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
| |||
31 | 30 | | |
32 | 31 | | |
33 | 32 | | |
34 | | - | |
| 33 | + | |
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
41 | 40 | | |
42 | | - | |
| 41 | + | |
43 | 42 | | |
44 | 43 | | |
45 | | - | |
46 | | - | |
| 44 | + | |
47 | 45 | | |
48 | 46 | | |
49 | 47 | | |
| |||
154 | 152 | | |
155 | 153 | | |
156 | 154 | | |
157 | | - | |
| 155 | + | |
158 | 156 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
170 | 163 | | |
171 | 164 | | |
172 | 165 | | |
| |||
197 | 190 | | |
198 | 191 | | |
199 | 192 | | |
200 | | - | |
| 193 | + | |
201 | 194 | | |
202 | 195 | | |
203 | 196 | | |
| |||
223 | 216 | | |
224 | 217 | | |
225 | 218 | | |
| 219 | + | |
226 | 220 | | |
227 | 221 | | |
228 | 222 | | |
| |||
237 | 231 | | |
238 | 232 | | |
239 | 233 | | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | 234 | | |
251 | 235 | | |
252 | 236 | | |
| |||
274 | 258 | | |
275 | 259 | | |
276 | 260 | | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | 261 | | |
294 | 262 | | |
295 | 263 | | |
| |||
298 | 266 | | |
299 | 267 | | |
300 | 268 | | |
301 | | - | |
| 269 | + | |
302 | 270 | | |
303 | 271 | | |
304 | 272 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
| 185 | + | |
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| |||
0 commit comments