Skip to content

Commit b1f64ee

Browse files
Python: Introducing the SQL Connector (#10981)
### 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 adds the Azure SQL Store and Collection Closes #9882 ### Description <!-- 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 😄
1 parent 57bf2be commit b1f64ee

File tree

7 files changed

+1666
-5
lines changed

7 files changed

+1666
-5
lines changed

python/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ realtime = [
138138
"websockets >= 13, < 16",
139139
"aiortc>=1.9.0",
140140
]
141+
sql = [
142+
"pyodbc >= 5.2"
143+
]
141144

142145
[tool.uv]
143146
prerelease = "if-necessary-or-explicit"

python/samples/concepts/memory/complex_memory.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from semantic_kernel.connectors.memory.postgres import PostgresCollection
3030
from semantic_kernel.connectors.memory.qdrant import QdrantCollection
3131
from semantic_kernel.connectors.memory.redis import RedisHashsetCollection, RedisJsonCollection
32+
from semantic_kernel.connectors.memory.sql_server import SqlServerCollection
3233
from semantic_kernel.connectors.memory.weaviate import WeaviateCollection
3334
from semantic_kernel.data import (
3435
VectorizableTextSearchMixin,
@@ -120,7 +121,7 @@ class DataModelList:
120121
# Depending on the vector database, the index kind and distance function may need to be adjusted
121122
# since not all combinations are supported by all databases.
122123
# The values below might need to be changed for your collection to work.
123-
distance_function = DistanceFunction.EUCLIDEAN_SQUARED_DISTANCE
124+
distance_function = DistanceFunction.COSINE_DISTANCE
124125
index_kind = IndexKind.FLAT
125126
DataModel = get_data_model("array", index_kind, distance_function)
126127

@@ -147,11 +148,14 @@ class DataModelList:
147148
# The chroma collection is currently only available for in-memory versions
148149
# Client-Server mode and Chroma Cloud are not yet supported.
149150
# More info on Chroma here: https://docs.trychroma.com/docs/overview/introduction
151+
# - faiss: Faiss - in-memory with optimized indexes.
152+
# - pinecone: Pinecone
153+
# - sql_server: SQL Server, can connect to any SQL Server compatible database, like Azure SQL.
150154
# This is represented as a mapping from the collection name to a
151155
# function which returns the collection.
152156
# Using a function allows for lazy initialization of the collection,
153157
# so that settings for unused collections do not cause validation errors.
154-
collections: dict[str, Callable[[], VectorStoreRecordCollection[str, DataModel]]] = {
158+
collections: dict[str, Callable[[], VectorStoreRecordCollection]] = {
155159
"ai_search": lambda: AzureAISearchCollection[str, DataModel](
156160
data_model_type=DataModel,
157161
),
@@ -204,6 +208,10 @@ class DataModelList:
204208
collection_name=collection_name,
205209
data_model_type=DataModel,
206210
),
211+
"sql_server": lambda: SqlServerCollection[str, DataModel](
212+
data_model_type=DataModel,
213+
collection_name=collection_name,
214+
),
207215
}
208216

209217

0 commit comments

Comments
 (0)