Commit 8b4ed96
Add Support for Vector Data Type in SQL for REST (#3677)
## Why make this change?
- Solves issue #3654
## What is this change?
These changes add the base to support the Vector data type for REST,
GraphQL, and MCP. This PR focuses mainly on the REST endpoint, ensuring
that it is able to both read and write to the vector columns through it.
Lastly, it also adds support to ensure that OpenAPI is able to show
columns with the Vector data type as `array: [numeric]`.
The following files were changed to show that DAB is able to support the
Vector data type and also change the type internally to system types it
can work with. Such as the `float` type for `DbType`, the `Numeric` type
for `JsonDataType`, and `SINGLE_TYPE` for GraphQL.
- SqlTypeConstants
- TypeHelper.cs
- SqlSchemaConverter.cs
The following file was changed to allow DAB to save the vector columns
as an array type, which is necessary for GraphQL to be able to know if
the column of an entity is a simple type or an array.
- MsSqlMetadataProvider.cs
The following files were changed to parse the information from the user
to a format that can be used by DAB to create the queries for SQL.
- BaseSqlQueryStructure.cs: Parses the array information by creating a
new function that checks for the simple type of the array (e.g If it is
an array of floats it will use the type float) and parse each value
inside the array.
- MsSqlQueryExecutor.cs: Parses the values given by the user and adds
them to an SqlVector object which allows for an easier way to query the
values.
The following file was changed to allow DAB's OpenAPI to support array
types by checking if the main type is `array` and then taking the
subtype and creating the appropriate item with it.
- OpenApiDocumentor.cs
Note: All of these changes are only applicable to Vectors of Float32,
support for Vectors of Float16 will have to wait as support for it in
.NET is still missing.
## How was this tested?
- [x] Integration Tests
- [ ] Unit Tests
Added tests that ensure the following scenarios on REST:
- Read regular vector
- Read vector with max number of dimensions possible
- Read vector with null value
- Read vector with `$first` argument
- Read vector with `$after` argument
- Read vector with `$filter` argument - fails
- Read vector with `$orderby` argument - fails
- Insert regular vector
- Insert vector with null value
- Insert vector with number values in scientific format
- Insert vector with number values in string format
- Insert vector with more dimensions than allowed - fails
- Insert vector with non-valid values - fails
- Update vector with new values
## Sample Request(s)
Note: Currently the values will be outputted in scientific notation,
this will be changed in the future
#3680
GET https://localhost:5001/api/dbo_normalvector/
<img width="429" height="609" alt="image"
src="https://github.com/user-attachments/assets/f0c16c4a-4e6a-4199-8d26-33469af2feab"
/>
POST https://localhost:5001/api/dbo_normalvector/
```
{
"ProductID": 2100,
"Embedding": [
1.15202468461012559910005,
0.00005,
5.111111111
]
}
```
<img width="303" height="319" alt="image"
src="https://github.com/user-attachments/assets/3b660ddd-dbe8-4f24-9025-fc526bbd64e4"
/>
PATCH https://localhost:5001/api/dbo_normalvector/ (Adding new row)
```
{
"ProductID": 3100,
"Embedding": [
1.15202468461012559910005,
0.00005,
5.111111111
]
}
```
<img width="472" height="318" alt="image"
src="https://github.com/user-attachments/assets/c22cf689-bf60-4a1f-934b-91bbad2de3ae"
/>
PATCH https://localhost:5001/api/dbo_normalvector/ (Update existing row)
```
{
"ProductID": 2100,
"Embedding": [
25,
1.2,
510.35
]
}
```
<img width="363" height="315" alt="image"
src="https://github.com/user-attachments/assets/7af1259b-834a-4881-a80f-ab011ee1123d"
/>
PUT https://localhost:5001/api/dbo_normalvector/ (Adding new row)
```
{
"ProductID": 4100,
"Embedding": [
0,
1,
37
]
}
```
<img width="310" height="289" alt="image"
src="https://github.com/user-attachments/assets/1aba2a11-5efe-443d-9f89-62b510fe4a42"
/>
PUT https://localhost:5001/api/dbo_normalvector/ (Edit existing row)
```
{
"ProductID": 2100,
"Embedding": [
0.220224962,
0.66666667,
37
]
}
```
<img width="386" height="303" alt="image"
src="https://github.com/user-attachments/assets/abf79182-716c-407f-af2a-0396e26a7c26"
/>
https://localhost:5001/swagger
<img width="348" height="142" alt="image"
src="https://github.com/user-attachments/assets/5d65470b-7df2-4725-a70d-ec9eeb69e7d0"
/>
<img width="302" height="277" alt="image"
src="https://github.com/user-attachments/assets/3b5c08b2-39ed-4bd8-a287-7b6fba3a7684"
/>
---------
Co-authored-by: souvikghosh04 <souvikofficial04@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: aaronburtle <93220300+aaronburtle@users.noreply.github.com>1 parent 0f80a0e commit 8b4ed96
13 files changed
Lines changed: 549 additions & 12 deletions
File tree
- config-generators
- src
- Core
- Models
- Resolvers
- Sql Query Structures
- Services
- MetadataProviders
- OpenAPI
- Service.Tests
- Snapshots
- SqlTests/RestApiTests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
666 | 666 | | |
667 | 667 | | |
668 | 668 | | |
669 | | - | |
670 | | - | |
| 669 | + | |
671 | 670 | | |
672 | 671 | | |
673 | 672 | | |
| |||
712 | 711 | | |
713 | 712 | | |
714 | 713 | | |
715 | | - | |
716 | | - | |
| 714 | + | |
717 | 715 | | |
718 | 716 | | |
719 | 717 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
695 | 696 | | |
696 | 697 | | |
697 | 698 | | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
698 | 712 | | |
699 | 713 | | |
700 | 714 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
502 | 503 | | |
503 | 504 | | |
504 | 505 | | |
505 | | - | |
| 506 | + | |
506 | 507 | | |
507 | 508 | | |
508 | 509 | | |
| |||
554 | 555 | | |
555 | 556 | | |
556 | 557 | | |
557 | | - | |
| 558 | + | |
558 | 559 | | |
559 | 560 | | |
560 | 561 | | |
| |||
822 | 823 | | |
823 | 824 | | |
824 | 825 | | |
825 | | - | |
| 826 | + | |
826 | 827 | | |
827 | 828 | | |
828 | 829 | | |
| |||
885 | 886 | | |
886 | 887 | | |
887 | 888 | | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
888 | 901 | | |
889 | 902 | | |
890 | 903 | | |
| |||
Lines changed: 40 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
452 | 453 | | |
453 | 454 | | |
454 | 455 | | |
| 456 | + | |
455 | 457 | | |
456 | 458 | | |
457 | 459 | | |
458 | 460 | | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
459 | 499 | | |
460 | 500 | | |
461 | 501 | | |
| |||
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
120 | 121 | | |
121 | 122 | | |
122 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
123 | 133 | | |
124 | 134 | | |
125 | 135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1484 | 1484 | | |
1485 | 1485 | | |
1486 | 1486 | | |
| 1487 | + | |
1487 | 1488 | | |
1488 | 1489 | | |
1489 | 1490 | | |
1490 | 1491 | | |
1491 | 1492 | | |
1492 | 1493 | | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
1493 | 1499 | | |
1494 | 1500 | | |
1495 | 1501 | | |
| |||
1502 | 1508 | | |
1503 | 1509 | | |
1504 | 1510 | | |
1505 | | - | |
| 1511 | + | |
| 1512 | + | |
1506 | 1513 | | |
1507 | 1514 | | |
1508 | 1515 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
49 | | - | |
| 50 | + | |
| 51 | + | |
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| |||
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
80 | | - | |
| 82 | + | |
| 83 | + | |
81 | 84 | | |
82 | 85 | | |
83 | 86 | | |
| |||
111 | 114 | | |
112 | 115 | | |
113 | 116 | | |
114 | | - | |
| 117 | + | |
| 118 | + | |
115 | 119 | | |
116 | 120 | | |
117 | 121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
234 | 235 | | |
235 | 236 | | |
236 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
237 | 244 | | |
238 | 245 | | |
239 | 246 | | |
| |||
616 | 623 | | |
617 | 624 | | |
618 | 625 | | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
619 | 643 | | |
620 | 644 | | |
621 | 645 | | |
| |||
0 commit comments