agent-framework-sql-server 1.0.0a261002__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agent_framework_sql_server-1.0.0a261002/LICENSE +21 -0
- agent_framework_sql_server-1.0.0a261002/PKG-INFO +195 -0
- agent_framework_sql_server-1.0.0a261002/README.md +170 -0
- agent_framework_sql_server-1.0.0a261002/agent_framework_sql_server/__init__.py +22 -0
- agent_framework_sql_server-1.0.0a261002/agent_framework_sql_server/_sql.py +344 -0
- agent_framework_sql_server-1.0.0a261002/agent_framework_sql_server/_vector_store.py +705 -0
- agent_framework_sql_server-1.0.0a261002/agent_framework_sql_server/py.typed +0 -0
- agent_framework_sql_server-1.0.0a261002/pyproject.toml +64 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-framework-sql-server
|
|
3
|
+
Version: 1.0.0a261002
|
|
4
|
+
Summary: SQL Server native vector integration for Microsoft Agent Framework.
|
|
5
|
+
Author-email: Microsoft <af-support@microsoft.com>
|
|
6
|
+
Requires-Python: >=3.10,<3.15
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: agent-framework-core>=1.19.0,<2
|
|
20
|
+
Requires-Dist: mssql-python>=1.15.0,<2
|
|
21
|
+
Project-URL: homepage, https://aka.ms/agent-framework
|
|
22
|
+
Project-URL: issues, https://github.com/microsoft/agent-framework/issues
|
|
23
|
+
Project-URL: source, https://github.com/microsoft/agent-framework/tree/main/python
|
|
24
|
+
|
|
25
|
+
# Agent Framework SQL Server vector store
|
|
26
|
+
|
|
27
|
+
Store typed Agent Framework records in SQL Server and Azure SQL native `VECTOR`
|
|
28
|
+
columns, with exact, database-side similarity search. This alpha package exports
|
|
29
|
+
`SqlServerCollection`, `SqlServerStore`, `SqlServerSettings`, and
|
|
30
|
+
`SqlServerCommittedCleanupException` directly from `agent_framework_sql_server`.
|
|
31
|
+
|
|
32
|
+
## Install and provision
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install agent-framework-sql-server --pre
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Requires Python 3.10–3.14 and a vector-enabled database: SQL Server 2025
|
|
39
|
+
(17.x), Azure SQL Database, Azure SQL Managed Instance on the SQL Server 2025
|
|
40
|
+
or Always-up-to-date update policy, or SQL database in Microsoft Fabric.
|
|
41
|
+
Older SQL Server releases do not support `VECTOR`/`VECTOR_DISTANCE`.
|
|
42
|
+
|
|
43
|
+
The package uses Microsoft's [`mssql-python` 1.15+ driver](https://pypi.org/project/mssql-python/).
|
|
44
|
+
It installs its `mssql-python-odbc` binary companion automatically; no external
|
|
45
|
+
ODBC Driver 18 or driver manager is required. Published wheels cover CPython
|
|
46
|
+
3.10–3.14 on Windows x64, Linux x64/ARM64, and **macOS 15+**
|
|
47
|
+
Intel/Apple Silicon; Windows ARM64 wheels start at Python 3.11. macOS 14 is
|
|
48
|
+
listed in the driver's support documentation, but the published macOS wheels
|
|
49
|
+
are tagged `macosx_15_0_universal2` and there is no source distribution.
|
|
50
|
+
Python 3.15 has no published wheel yet: this package caps `requires-python`
|
|
51
|
+
below 3.15, and the repository's non-blocking 3.15 CI lane excludes it.
|
|
52
|
+
The workspace lockfile likewise limits Python below 3.15 while this package
|
|
53
|
+
remains a member; the experimental 3.15 lane excludes it before resolving.
|
|
54
|
+
Follow the [driver's installation instructions](https://learn.microsoft.com/sql/connect/python/mssql-python/installation)
|
|
55
|
+
for system libraries on Linux and OpenSSL on macOS.
|
|
56
|
+
|
|
57
|
+
The database administrator must provide an existing schema (default `dbo`).
|
|
58
|
+
`ensure_collection_exists()` creates the requested table and scalar indexes
|
|
59
|
+
there but never creates a schema, alters an existing table, or changes database
|
|
60
|
+
settings. `ensure_collection_deleted()` drops only that table.
|
|
61
|
+
|
|
62
|
+
## Connection settings and ownership
|
|
63
|
+
|
|
64
|
+
For local Azure SQL development with passwordless Microsoft Entra authentication,
|
|
65
|
+
sign in with Azure CLI, then set the environment variable used by the
|
|
66
|
+
[sample](samples/sql_server_vectors.py):
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
az login
|
|
70
|
+
export SQL_SERVER_CONNECTION_STRING='Server=<host>;Database=<db>;Authentication=ActiveDirectoryDefault;Encrypt=yes;'
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Replace `<host>` with the Azure SQL server hostname (for example,
|
|
74
|
+
`my-server.database.windows.net`) and `<db>` with your existing database.
|
|
75
|
+
`ActiveDirectoryDefault` uses the driver's credential chain, which can use
|
|
76
|
+
your Azure CLI sign-in. The identity must be granted access to the database
|
|
77
|
+
and permission to create a table and index in the configured schema and
|
|
78
|
+
read/write its records. On an Azure-hosted app, use
|
|
79
|
+
`Authentication=ActiveDirectoryMSI` for managed identity; add
|
|
80
|
+
`UID=<client-id>` for a user-assigned identity. See
|
|
81
|
+
[Microsoft's Entra authentication guide](https://learn.microsoft.com/sql/connect/python/mssql-python/entra-authentication)
|
|
82
|
+
for setup, permissions, and other supported modes. This connector accepts
|
|
83
|
+
connection strings, not the driver's `token_provider=` credential argument.
|
|
84
|
+
|
|
85
|
+
Do not commit connection strings containing credentials. Alternatively, pass
|
|
86
|
+
`connection_string` as a string or Agent Framework `SecretString` to
|
|
87
|
+
`SqlServerStore` or `SqlServerCollection`. Settings precedence is **explicit
|
|
88
|
+
argument > selected `.env` file > process environment**. To read a `.env` file
|
|
89
|
+
in the run directory, pass `env_file_path=".env"` to `SqlServerStore` or
|
|
90
|
+
`SqlServerCollection`; `env_file_encoding` is optional. Missing or empty
|
|
91
|
+
connection strings are rejected.
|
|
92
|
+
|
|
93
|
+
The connector owns all connections. Each whole operation opens, uses, commits
|
|
94
|
+
or rolls back, and closes a `mssql-python` connection on a dedicated worker
|
|
95
|
+
thread, keeping Agent Framework's async calls nonblocking. The driver's
|
|
96
|
+
built-in pooling can reuse the underlying physical connection. A store and
|
|
97
|
+
its collections share one worker; a standalone collection owns its own.
|
|
98
|
+
Call `close()` or use an async context manager to release the worker. There is
|
|
99
|
+
no `client=` or connection-factory constructor argument: arbitrary caller-owned
|
|
100
|
+
`mssql-python` connections cannot safely cross threads (`threadsafety=1`).
|
|
101
|
+
This is intentionally narrower than connectors that support borrowed async
|
|
102
|
+
clients.
|
|
103
|
+
|
|
104
|
+
Batch writes commit or roll back together on one connection. Cancelling an
|
|
105
|
+
async operation waits for its worker to finish cleanup; it cannot interrupt an
|
|
106
|
+
already-running synchronous SQL statement, and the transaction may already
|
|
107
|
+
have committed. Set `query_timeout=30` (seconds, for example) on the store or
|
|
108
|
+
collection when bounding database calls; leaving it unset uses the driver's
|
|
109
|
+
default, and `0` disables the timeout. Prefer stable application-provided
|
|
110
|
+
keys when retrying writes.
|
|
111
|
+
If closing the connection fails after a successful commit,
|
|
112
|
+
`SqlServerCommittedCleanupException` explicitly signals that the transaction
|
|
113
|
+
**already committed**; do not automatically retry, especially with generated
|
|
114
|
+
keys. Cancellation remains `CancelledError` even if the worker fails while
|
|
115
|
+
finishing; that worker error is logged after cleanup.
|
|
116
|
+
|
|
117
|
+
## Example
|
|
118
|
+
|
|
119
|
+
With `SQL_SERVER_CONNECTION_STRING` configured, run the
|
|
120
|
+
[typed sample](samples/sql_server_vectors.py) from the `python/` directory:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
uv run --package agent-framework-sql-server \
|
|
124
|
+
python packages/sql-server/samples/sql_server_vectors.py
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The sample creates a uniquely named table, upserts precomputed embeddings,
|
|
128
|
+
filters/ranks in SQL Server, retrieves an optional vector, and drops its own
|
|
129
|
+
table. Pass `generate_vectors=False` to preserve precomputed vectors; to
|
|
130
|
+
generate them locally, configure an `embedding_generator`.
|
|
131
|
+
|
|
132
|
+
## Capabilities and limits
|
|
133
|
+
|
|
134
|
+
The connector supports typed decorated models and dictionary definitions;
|
|
135
|
+
string/integer/UUID keys (including generated keys); multiple nullable float32
|
|
136
|
+
vector columns with **1–1998 dimensions**; field storage aliases; batch
|
|
137
|
+
upsert/get/delete; paged and ordered retrieval; scalar data indexes; and
|
|
138
|
+
parameterized top-level `Filter`/`FilterGroup` expressions. String keys cannot
|
|
139
|
+
end with a space because SQL Server ignores trailing spaces in key comparisons.
|
|
140
|
+
Indexed strings use `NVARCHAR(450)`; other strings use `NVARCHAR(MAX)`. List and
|
|
141
|
+
dictionary fields are stored as JSON, and timezone-aware `datetime` values are
|
|
142
|
+
normalized to UTC in `DATETIME2(7)` columns.
|
|
143
|
+
For an auto-generated integer (`IDENTITY`) key, omit the key on insert;
|
|
144
|
+
explicit keys can update existing rows but cannot create new identity rows.
|
|
145
|
+
|
|
146
|
+
Supported filters: scalar `eq`, `ne`, `in`, `not_in`, `is_null`, `is_not_null`,
|
|
147
|
+
`exists`; numeric/date/datetime `gt`, `gte`, `lt`, `lte`, `between`; and string
|
|
148
|
+
`starts_with`, `ends_with`, `contains_text`. `AND`/`OR`/`NOT` groups preserve
|
|
149
|
+
two-valued null semantics; string equality is byte-exact and text patterns
|
|
150
|
+
escape SQL Server wildcards. JSON fields support `is_null`, `is_not_null`, and
|
|
151
|
+
`exists`, **not** equality or collection-membership filters. Nested paths,
|
|
152
|
+
full-text filtering, and unknown operation options fail explicitly. The SQL
|
|
153
|
+
Server 2100-parameter limit is respected by batching key reads/deletes and
|
|
154
|
+
limiting other statements to 2000 bound parameters.
|
|
155
|
+
|
|
156
|
+
Search uses SQL Server's exact `VECTOR_DISTANCE` on native `VECTOR` columns,
|
|
157
|
+
with filters and score thresholds applied **before** offset/limit. The default
|
|
158
|
+
metric is cosine **distance** (lower is better). Euclidean and negative dot
|
|
159
|
+
product also return distances (maximum thresholds); `cosine_similarity` and
|
|
160
|
+
`dot_prod` return similarity/positive-dot scores (minimum thresholds).
|
|
161
|
+
Scores are raw metric units, not probabilities. Retrieval excludes vectors by
|
|
162
|
+
default; use `include_vectors=True` to return them. Approximate DiskANN
|
|
163
|
+
indexes/search, preview-only float16 vectors, keyword-hybrid search, sparse or
|
|
164
|
+
binary vectors, server-side embedding generation, and schema migration are
|
|
165
|
+
not supported.
|
|
166
|
+
|
|
167
|
+
The server stores native `VECTOR` columns, but `mssql-python` 1.15 does not
|
|
168
|
+
expose a native Python vector type. The connector binds JSON-encoded vectors
|
|
169
|
+
as parameters and parses JSON on retrieval; SQL Server converts to/from the
|
|
170
|
+
native type. It does not enable native driver vector bindings.
|
|
171
|
+
|
|
172
|
+
## Service tests
|
|
173
|
+
|
|
174
|
+
Unit tests need no database. Integration tests are opt-in: set
|
|
175
|
+
`SQL_SERVER_TEST_CONNECTION_STRING` to a deliberately designated test database
|
|
176
|
+
with table creation permissions and run:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
uv run --package agent-framework-sql-server pytest \
|
|
180
|
+
packages/sql-server/tests/sql_server/test_integration.py -m integration
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
The tests create uniquely named tables and remove only those tables. They
|
|
184
|
+
skip when the variable is absent or empty (including an unconfigured CI
|
|
185
|
+
secret), and fail rather than silently skipping when an explicitly
|
|
186
|
+
designated server lacks vector support.
|
|
187
|
+
|
|
188
|
+
## References
|
|
189
|
+
|
|
190
|
+
- [SQL Server vector type and database availability](https://learn.microsoft.com/sql/t-sql/data-types/vector-data-type)
|
|
191
|
+
- [Exact vector distance metrics](https://learn.microsoft.com/sql/t-sql/functions/vector-distance-transact-sql)
|
|
192
|
+
- [Microsoft's Python vector JSON example](https://learn.microsoft.com/sql/t-sql/data-types/vector-data-type#python)
|
|
193
|
+
- [mssql-python asynchronous integration patterns](https://learn.microsoft.com/sql/connect/python/mssql-python/asynchronous-patterns)
|
|
194
|
+
- [Microsoft Agent Framework](https://learn.microsoft.com/agent-framework/)
|
|
195
|
+
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# Agent Framework SQL Server vector store
|
|
2
|
+
|
|
3
|
+
Store typed Agent Framework records in SQL Server and Azure SQL native `VECTOR`
|
|
4
|
+
columns, with exact, database-side similarity search. This alpha package exports
|
|
5
|
+
`SqlServerCollection`, `SqlServerStore`, `SqlServerSettings`, and
|
|
6
|
+
`SqlServerCommittedCleanupException` directly from `agent_framework_sql_server`.
|
|
7
|
+
|
|
8
|
+
## Install and provision
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pip install agent-framework-sql-server --pre
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Requires Python 3.10–3.14 and a vector-enabled database: SQL Server 2025
|
|
15
|
+
(17.x), Azure SQL Database, Azure SQL Managed Instance on the SQL Server 2025
|
|
16
|
+
or Always-up-to-date update policy, or SQL database in Microsoft Fabric.
|
|
17
|
+
Older SQL Server releases do not support `VECTOR`/`VECTOR_DISTANCE`.
|
|
18
|
+
|
|
19
|
+
The package uses Microsoft's [`mssql-python` 1.15+ driver](https://pypi.org/project/mssql-python/).
|
|
20
|
+
It installs its `mssql-python-odbc` binary companion automatically; no external
|
|
21
|
+
ODBC Driver 18 or driver manager is required. Published wheels cover CPython
|
|
22
|
+
3.10–3.14 on Windows x64, Linux x64/ARM64, and **macOS 15+**
|
|
23
|
+
Intel/Apple Silicon; Windows ARM64 wheels start at Python 3.11. macOS 14 is
|
|
24
|
+
listed in the driver's support documentation, but the published macOS wheels
|
|
25
|
+
are tagged `macosx_15_0_universal2` and there is no source distribution.
|
|
26
|
+
Python 3.15 has no published wheel yet: this package caps `requires-python`
|
|
27
|
+
below 3.15, and the repository's non-blocking 3.15 CI lane excludes it.
|
|
28
|
+
The workspace lockfile likewise limits Python below 3.15 while this package
|
|
29
|
+
remains a member; the experimental 3.15 lane excludes it before resolving.
|
|
30
|
+
Follow the [driver's installation instructions](https://learn.microsoft.com/sql/connect/python/mssql-python/installation)
|
|
31
|
+
for system libraries on Linux and OpenSSL on macOS.
|
|
32
|
+
|
|
33
|
+
The database administrator must provide an existing schema (default `dbo`).
|
|
34
|
+
`ensure_collection_exists()` creates the requested table and scalar indexes
|
|
35
|
+
there but never creates a schema, alters an existing table, or changes database
|
|
36
|
+
settings. `ensure_collection_deleted()` drops only that table.
|
|
37
|
+
|
|
38
|
+
## Connection settings and ownership
|
|
39
|
+
|
|
40
|
+
For local Azure SQL development with passwordless Microsoft Entra authentication,
|
|
41
|
+
sign in with Azure CLI, then set the environment variable used by the
|
|
42
|
+
[sample](samples/sql_server_vectors.py):
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
az login
|
|
46
|
+
export SQL_SERVER_CONNECTION_STRING='Server=<host>;Database=<db>;Authentication=ActiveDirectoryDefault;Encrypt=yes;'
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Replace `<host>` with the Azure SQL server hostname (for example,
|
|
50
|
+
`my-server.database.windows.net`) and `<db>` with your existing database.
|
|
51
|
+
`ActiveDirectoryDefault` uses the driver's credential chain, which can use
|
|
52
|
+
your Azure CLI sign-in. The identity must be granted access to the database
|
|
53
|
+
and permission to create a table and index in the configured schema and
|
|
54
|
+
read/write its records. On an Azure-hosted app, use
|
|
55
|
+
`Authentication=ActiveDirectoryMSI` for managed identity; add
|
|
56
|
+
`UID=<client-id>` for a user-assigned identity. See
|
|
57
|
+
[Microsoft's Entra authentication guide](https://learn.microsoft.com/sql/connect/python/mssql-python/entra-authentication)
|
|
58
|
+
for setup, permissions, and other supported modes. This connector accepts
|
|
59
|
+
connection strings, not the driver's `token_provider=` credential argument.
|
|
60
|
+
|
|
61
|
+
Do not commit connection strings containing credentials. Alternatively, pass
|
|
62
|
+
`connection_string` as a string or Agent Framework `SecretString` to
|
|
63
|
+
`SqlServerStore` or `SqlServerCollection`. Settings precedence is **explicit
|
|
64
|
+
argument > selected `.env` file > process environment**. To read a `.env` file
|
|
65
|
+
in the run directory, pass `env_file_path=".env"` to `SqlServerStore` or
|
|
66
|
+
`SqlServerCollection`; `env_file_encoding` is optional. Missing or empty
|
|
67
|
+
connection strings are rejected.
|
|
68
|
+
|
|
69
|
+
The connector owns all connections. Each whole operation opens, uses, commits
|
|
70
|
+
or rolls back, and closes a `mssql-python` connection on a dedicated worker
|
|
71
|
+
thread, keeping Agent Framework's async calls nonblocking. The driver's
|
|
72
|
+
built-in pooling can reuse the underlying physical connection. A store and
|
|
73
|
+
its collections share one worker; a standalone collection owns its own.
|
|
74
|
+
Call `close()` or use an async context manager to release the worker. There is
|
|
75
|
+
no `client=` or connection-factory constructor argument: arbitrary caller-owned
|
|
76
|
+
`mssql-python` connections cannot safely cross threads (`threadsafety=1`).
|
|
77
|
+
This is intentionally narrower than connectors that support borrowed async
|
|
78
|
+
clients.
|
|
79
|
+
|
|
80
|
+
Batch writes commit or roll back together on one connection. Cancelling an
|
|
81
|
+
async operation waits for its worker to finish cleanup; it cannot interrupt an
|
|
82
|
+
already-running synchronous SQL statement, and the transaction may already
|
|
83
|
+
have committed. Set `query_timeout=30` (seconds, for example) on the store or
|
|
84
|
+
collection when bounding database calls; leaving it unset uses the driver's
|
|
85
|
+
default, and `0` disables the timeout. Prefer stable application-provided
|
|
86
|
+
keys when retrying writes.
|
|
87
|
+
If closing the connection fails after a successful commit,
|
|
88
|
+
`SqlServerCommittedCleanupException` explicitly signals that the transaction
|
|
89
|
+
**already committed**; do not automatically retry, especially with generated
|
|
90
|
+
keys. Cancellation remains `CancelledError` even if the worker fails while
|
|
91
|
+
finishing; that worker error is logged after cleanup.
|
|
92
|
+
|
|
93
|
+
## Example
|
|
94
|
+
|
|
95
|
+
With `SQL_SERVER_CONNECTION_STRING` configured, run the
|
|
96
|
+
[typed sample](samples/sql_server_vectors.py) from the `python/` directory:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
uv run --package agent-framework-sql-server \
|
|
100
|
+
python packages/sql-server/samples/sql_server_vectors.py
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The sample creates a uniquely named table, upserts precomputed embeddings,
|
|
104
|
+
filters/ranks in SQL Server, retrieves an optional vector, and drops its own
|
|
105
|
+
table. Pass `generate_vectors=False` to preserve precomputed vectors; to
|
|
106
|
+
generate them locally, configure an `embedding_generator`.
|
|
107
|
+
|
|
108
|
+
## Capabilities and limits
|
|
109
|
+
|
|
110
|
+
The connector supports typed decorated models and dictionary definitions;
|
|
111
|
+
string/integer/UUID keys (including generated keys); multiple nullable float32
|
|
112
|
+
vector columns with **1–1998 dimensions**; field storage aliases; batch
|
|
113
|
+
upsert/get/delete; paged and ordered retrieval; scalar data indexes; and
|
|
114
|
+
parameterized top-level `Filter`/`FilterGroup` expressions. String keys cannot
|
|
115
|
+
end with a space because SQL Server ignores trailing spaces in key comparisons.
|
|
116
|
+
Indexed strings use `NVARCHAR(450)`; other strings use `NVARCHAR(MAX)`. List and
|
|
117
|
+
dictionary fields are stored as JSON, and timezone-aware `datetime` values are
|
|
118
|
+
normalized to UTC in `DATETIME2(7)` columns.
|
|
119
|
+
For an auto-generated integer (`IDENTITY`) key, omit the key on insert;
|
|
120
|
+
explicit keys can update existing rows but cannot create new identity rows.
|
|
121
|
+
|
|
122
|
+
Supported filters: scalar `eq`, `ne`, `in`, `not_in`, `is_null`, `is_not_null`,
|
|
123
|
+
`exists`; numeric/date/datetime `gt`, `gte`, `lt`, `lte`, `between`; and string
|
|
124
|
+
`starts_with`, `ends_with`, `contains_text`. `AND`/`OR`/`NOT` groups preserve
|
|
125
|
+
two-valued null semantics; string equality is byte-exact and text patterns
|
|
126
|
+
escape SQL Server wildcards. JSON fields support `is_null`, `is_not_null`, and
|
|
127
|
+
`exists`, **not** equality or collection-membership filters. Nested paths,
|
|
128
|
+
full-text filtering, and unknown operation options fail explicitly. The SQL
|
|
129
|
+
Server 2100-parameter limit is respected by batching key reads/deletes and
|
|
130
|
+
limiting other statements to 2000 bound parameters.
|
|
131
|
+
|
|
132
|
+
Search uses SQL Server's exact `VECTOR_DISTANCE` on native `VECTOR` columns,
|
|
133
|
+
with filters and score thresholds applied **before** offset/limit. The default
|
|
134
|
+
metric is cosine **distance** (lower is better). Euclidean and negative dot
|
|
135
|
+
product also return distances (maximum thresholds); `cosine_similarity` and
|
|
136
|
+
`dot_prod` return similarity/positive-dot scores (minimum thresholds).
|
|
137
|
+
Scores are raw metric units, not probabilities. Retrieval excludes vectors by
|
|
138
|
+
default; use `include_vectors=True` to return them. Approximate DiskANN
|
|
139
|
+
indexes/search, preview-only float16 vectors, keyword-hybrid search, sparse or
|
|
140
|
+
binary vectors, server-side embedding generation, and schema migration are
|
|
141
|
+
not supported.
|
|
142
|
+
|
|
143
|
+
The server stores native `VECTOR` columns, but `mssql-python` 1.15 does not
|
|
144
|
+
expose a native Python vector type. The connector binds JSON-encoded vectors
|
|
145
|
+
as parameters and parses JSON on retrieval; SQL Server converts to/from the
|
|
146
|
+
native type. It does not enable native driver vector bindings.
|
|
147
|
+
|
|
148
|
+
## Service tests
|
|
149
|
+
|
|
150
|
+
Unit tests need no database. Integration tests are opt-in: set
|
|
151
|
+
`SQL_SERVER_TEST_CONNECTION_STRING` to a deliberately designated test database
|
|
152
|
+
with table creation permissions and run:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
uv run --package agent-framework-sql-server pytest \
|
|
156
|
+
packages/sql-server/tests/sql_server/test_integration.py -m integration
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
The tests create uniquely named tables and remove only those tables. They
|
|
160
|
+
skip when the variable is absent or empty (including an unconfigured CI
|
|
161
|
+
secret), and fail rather than silently skipping when an explicitly
|
|
162
|
+
designated server lacks vector support.
|
|
163
|
+
|
|
164
|
+
## References
|
|
165
|
+
|
|
166
|
+
- [SQL Server vector type and database availability](https://learn.microsoft.com/sql/t-sql/data-types/vector-data-type)
|
|
167
|
+
- [Exact vector distance metrics](https://learn.microsoft.com/sql/t-sql/functions/vector-distance-transact-sql)
|
|
168
|
+
- [Microsoft's Python vector JSON example](https://learn.microsoft.com/sql/t-sql/data-types/vector-data-type#python)
|
|
169
|
+
- [mssql-python asynchronous integration patterns](https://learn.microsoft.com/sql/connect/python/mssql-python/asynchronous-patterns)
|
|
170
|
+
- [Microsoft Agent Framework](https://learn.microsoft.com/agent-framework/)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Copyright (c) Microsoft. All rights reserved.
|
|
2
|
+
|
|
3
|
+
"""SQL Server native vector collections and stores for Agent Framework."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import importlib.metadata
|
|
8
|
+
|
|
9
|
+
from ._vector_store import SqlServerCollection, SqlServerCommittedCleanupException, SqlServerSettings, SqlServerStore
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
__version__ = importlib.metadata.version(__name__)
|
|
13
|
+
except importlib.metadata.PackageNotFoundError:
|
|
14
|
+
__version__ = "0.0.0"
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"SqlServerCollection",
|
|
18
|
+
"SqlServerCommittedCleanupException",
|
|
19
|
+
"SqlServerSettings",
|
|
20
|
+
"SqlServerStore",
|
|
21
|
+
"__version__",
|
|
22
|
+
]
|