agent-framework-azure-documentdb 1.0.0a260918__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_azure_documentdb-1.0.0a260918/LICENSE +21 -0
- agent_framework_azure_documentdb-1.0.0a260918/PKG-INFO +139 -0
- agent_framework_azure_documentdb-1.0.0a260918/README.md +114 -0
- agent_framework_azure_documentdb-1.0.0a260918/agent_framework_azure_documentdb/__init__.py +21 -0
- agent_framework_azure_documentdb-1.0.0a260918/agent_framework_azure_documentdb/_vector_store.py +1205 -0
- agent_framework_azure_documentdb-1.0.0a260918/agent_framework_azure_documentdb/py.typed +0 -0
- agent_framework_azure_documentdb-1.0.0a260918/pyproject.toml +66 -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,139 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-framework-azure-documentdb
|
|
3
|
+
Version: 1.0.0a260918
|
|
4
|
+
Summary: Azure DocumentDB vector stores for Microsoft Agent Framework.
|
|
5
|
+
Author-email: Microsoft <af-support@microsoft.com>
|
|
6
|
+
Requires-Python: >=3.10
|
|
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: pymongo>=4.13,<5
|
|
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 Azure DocumentDB
|
|
26
|
+
|
|
27
|
+
Store and search vector records in
|
|
28
|
+
[Azure DocumentDB](https://learn.microsoft.com/azure/documentdb/) with this
|
|
29
|
+
alpha integration for
|
|
30
|
+
[Microsoft Agent Framework](https://learn.microsoft.com/agent-framework/).
|
|
31
|
+
The package uses PyMongo's stable asynchronous API and Azure DocumentDB's
|
|
32
|
+
Mongo-compatible `$search.cosmosSearch` dialect.
|
|
33
|
+
|
|
34
|
+
- **`AzureDocumentDBCollection`** provides batch CRUD, metadata filters, index reconciliation, and vector search.
|
|
35
|
+
- **`AzureDocumentDBStore`** creates collection clients sharing one resolved database.
|
|
36
|
+
- **`AzureDocumentDBSettings`** defines the two Agent Framework-managed connection settings.
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install agent-framework-azure-documentdb --pre
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Requires Python 3.10+, PyMongo 4.13+, and an Azure DocumentDB cluster. IVF
|
|
45
|
+
indexes are intended for smaller datasets and M10/M20 tiers. HNSW and DiskANN
|
|
46
|
+
require M30 or higher; consult the current service documentation before choosing
|
|
47
|
+
a production tier.
|
|
48
|
+
|
|
49
|
+
## Authentication and setup
|
|
50
|
+
|
|
51
|
+
Set `AZURE_DOCUMENTDB_CONNECTION_STRING` to the connection string from the
|
|
52
|
+
Azure portal and `AZURE_DOCUMENTDB_DATABASE_NAME` to an existing or intended
|
|
53
|
+
database. Settings precedence is explicit constructor value, selected `.env`
|
|
54
|
+
file, then process environment. Connection strings are held in Agent Framework
|
|
55
|
+
`SecretString` values.
|
|
56
|
+
|
|
57
|
+
Connector-created clients enforce TLS, disable retryable writes, and set an
|
|
58
|
+
application name. They are closed by `aclose()` or an async context manager.
|
|
59
|
+
An injected PyMongo `AsyncMongoClient`, `AsyncDatabase`, or `AsyncCollection`
|
|
60
|
+
remains caller-owned and bypasses settings loading.
|
|
61
|
+
|
|
62
|
+
The identity running `ensure_collection_exists()` needs permission to create
|
|
63
|
+
collections and indexes. Each filtered data field must declare
|
|
64
|
+
`is_indexed=True`; the connector creates its ordinary ascending index alongside
|
|
65
|
+
separate vector indexes.
|
|
66
|
+
|
|
67
|
+
## Example
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
import asyncio
|
|
71
|
+
from dataclasses import dataclass
|
|
72
|
+
from typing import Annotated
|
|
73
|
+
|
|
74
|
+
from agent_framework import Filter, VectorStoreField, vectorstoremodel
|
|
75
|
+
from agent_framework_azure_documentdb import AzureDocumentDBStore
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@vectorstoremodel(collection_name="articles")
|
|
79
|
+
@dataclass
|
|
80
|
+
class Article:
|
|
81
|
+
id: Annotated[str, VectorStoreField("key")]
|
|
82
|
+
category: Annotated[str, VectorStoreField("data", is_indexed=True)]
|
|
83
|
+
embedding: Annotated[
|
|
84
|
+
list[float] | None,
|
|
85
|
+
VectorStoreField("vector", dimensions=3, index_kind="ivf_flat"),
|
|
86
|
+
] = None
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
async def main() -> None:
|
|
90
|
+
async with AzureDocumentDBStore() as store:
|
|
91
|
+
collection = store.get_collection(Article)
|
|
92
|
+
await collection.ensure_collection_exists()
|
|
93
|
+
await collection.upsert(
|
|
94
|
+
[Article("one", "database", [1.0, 0.0, 0.0])],
|
|
95
|
+
generate_vectors=False,
|
|
96
|
+
)
|
|
97
|
+
results = await collection.search(
|
|
98
|
+
vector=[1.0, 0.0, 0.0],
|
|
99
|
+
filter=Filter("category", "eq", "database"),
|
|
100
|
+
)
|
|
101
|
+
async for result in results:
|
|
102
|
+
print(result["record"], result["score"])
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
asyncio.run(main())
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Limits
|
|
109
|
+
|
|
110
|
+
The connector supports explicit string and signed 64-bit integer `_id` keys,
|
|
111
|
+
multiple top-level dense vector fields, storage aliases, IVF/HNSW/DiskANN
|
|
112
|
+
indexes, native metadata filters, server-side paging, and native `searchScore`
|
|
113
|
+
values. Generated ObjectIds, ordered retrieval, hybrid/full-text search,
|
|
114
|
+
sparse/binary vectors, nested field paths, compressed vectors, and automatic
|
|
115
|
+
schema/index migration are not supported.
|
|
116
|
+
|
|
117
|
+
The core `default` index kind maps to IVF so it does not silently require an
|
|
118
|
+
M30+ tier. Select `hnsw` or `disk_ann` explicitly when those service contracts
|
|
119
|
+
and cluster requirements are appropriate.
|
|
120
|
+
|
|
121
|
+
Vector dimensions are conservatively limited to the service's 2,000-dimension
|
|
122
|
+
standard-vector contract. Azure DocumentDB also offers higher limits with
|
|
123
|
+
half-precision or product quantization; those distinct index/storage options are
|
|
124
|
+
outside this connector.
|
|
125
|
+
|
|
126
|
+
`score_threshold` uses native metric units after `$search` selects its `k`
|
|
127
|
+
candidates and before `$skip`/`$limit`. It is a minimum for cosine and inner
|
|
128
|
+
product scores, where larger is better, and a maximum for Euclidean distance,
|
|
129
|
+
where smaller is better. Set a larger `operation_options={"k": ...}` candidate
|
|
130
|
+
window when needed. Thresholded ANN search can return fewer than `top`; the
|
|
131
|
+
connector does not fetch or filter a client-side prefix. Algorithm tuning uses
|
|
132
|
+
`n_probes`, `ef_search`, or `l_search` for IVF, HNSW, or DiskANN respectively.
|
|
133
|
+
|
|
134
|
+
See the
|
|
135
|
+
[Azure DocumentDB vector search guide](https://learn.microsoft.com/azure/documentdb/vector-search),
|
|
136
|
+
[Azure DocumentDB limits](https://learn.microsoft.com/azure/documentdb/limitations),
|
|
137
|
+
[PyMongo async API](https://pymongo.readthedocs.io/en/stable/api/pymongo/asynchronous/),
|
|
138
|
+
and [Agent Framework documentation](https://learn.microsoft.com/agent-framework/).
|
|
139
|
+
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# Agent Framework Azure DocumentDB
|
|
2
|
+
|
|
3
|
+
Store and search vector records in
|
|
4
|
+
[Azure DocumentDB](https://learn.microsoft.com/azure/documentdb/) with this
|
|
5
|
+
alpha integration for
|
|
6
|
+
[Microsoft Agent Framework](https://learn.microsoft.com/agent-framework/).
|
|
7
|
+
The package uses PyMongo's stable asynchronous API and Azure DocumentDB's
|
|
8
|
+
Mongo-compatible `$search.cosmosSearch` dialect.
|
|
9
|
+
|
|
10
|
+
- **`AzureDocumentDBCollection`** provides batch CRUD, metadata filters, index reconciliation, and vector search.
|
|
11
|
+
- **`AzureDocumentDBStore`** creates collection clients sharing one resolved database.
|
|
12
|
+
- **`AzureDocumentDBSettings`** defines the two Agent Framework-managed connection settings.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install agent-framework-azure-documentdb --pre
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Requires Python 3.10+, PyMongo 4.13+, and an Azure DocumentDB cluster. IVF
|
|
21
|
+
indexes are intended for smaller datasets and M10/M20 tiers. HNSW and DiskANN
|
|
22
|
+
require M30 or higher; consult the current service documentation before choosing
|
|
23
|
+
a production tier.
|
|
24
|
+
|
|
25
|
+
## Authentication and setup
|
|
26
|
+
|
|
27
|
+
Set `AZURE_DOCUMENTDB_CONNECTION_STRING` to the connection string from the
|
|
28
|
+
Azure portal and `AZURE_DOCUMENTDB_DATABASE_NAME` to an existing or intended
|
|
29
|
+
database. Settings precedence is explicit constructor value, selected `.env`
|
|
30
|
+
file, then process environment. Connection strings are held in Agent Framework
|
|
31
|
+
`SecretString` values.
|
|
32
|
+
|
|
33
|
+
Connector-created clients enforce TLS, disable retryable writes, and set an
|
|
34
|
+
application name. They are closed by `aclose()` or an async context manager.
|
|
35
|
+
An injected PyMongo `AsyncMongoClient`, `AsyncDatabase`, or `AsyncCollection`
|
|
36
|
+
remains caller-owned and bypasses settings loading.
|
|
37
|
+
|
|
38
|
+
The identity running `ensure_collection_exists()` needs permission to create
|
|
39
|
+
collections and indexes. Each filtered data field must declare
|
|
40
|
+
`is_indexed=True`; the connector creates its ordinary ascending index alongside
|
|
41
|
+
separate vector indexes.
|
|
42
|
+
|
|
43
|
+
## Example
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
import asyncio
|
|
47
|
+
from dataclasses import dataclass
|
|
48
|
+
from typing import Annotated
|
|
49
|
+
|
|
50
|
+
from agent_framework import Filter, VectorStoreField, vectorstoremodel
|
|
51
|
+
from agent_framework_azure_documentdb import AzureDocumentDBStore
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@vectorstoremodel(collection_name="articles")
|
|
55
|
+
@dataclass
|
|
56
|
+
class Article:
|
|
57
|
+
id: Annotated[str, VectorStoreField("key")]
|
|
58
|
+
category: Annotated[str, VectorStoreField("data", is_indexed=True)]
|
|
59
|
+
embedding: Annotated[
|
|
60
|
+
list[float] | None,
|
|
61
|
+
VectorStoreField("vector", dimensions=3, index_kind="ivf_flat"),
|
|
62
|
+
] = None
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
async def main() -> None:
|
|
66
|
+
async with AzureDocumentDBStore() as store:
|
|
67
|
+
collection = store.get_collection(Article)
|
|
68
|
+
await collection.ensure_collection_exists()
|
|
69
|
+
await collection.upsert(
|
|
70
|
+
[Article("one", "database", [1.0, 0.0, 0.0])],
|
|
71
|
+
generate_vectors=False,
|
|
72
|
+
)
|
|
73
|
+
results = await collection.search(
|
|
74
|
+
vector=[1.0, 0.0, 0.0],
|
|
75
|
+
filter=Filter("category", "eq", "database"),
|
|
76
|
+
)
|
|
77
|
+
async for result in results:
|
|
78
|
+
print(result["record"], result["score"])
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
asyncio.run(main())
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Limits
|
|
85
|
+
|
|
86
|
+
The connector supports explicit string and signed 64-bit integer `_id` keys,
|
|
87
|
+
multiple top-level dense vector fields, storage aliases, IVF/HNSW/DiskANN
|
|
88
|
+
indexes, native metadata filters, server-side paging, and native `searchScore`
|
|
89
|
+
values. Generated ObjectIds, ordered retrieval, hybrid/full-text search,
|
|
90
|
+
sparse/binary vectors, nested field paths, compressed vectors, and automatic
|
|
91
|
+
schema/index migration are not supported.
|
|
92
|
+
|
|
93
|
+
The core `default` index kind maps to IVF so it does not silently require an
|
|
94
|
+
M30+ tier. Select `hnsw` or `disk_ann` explicitly when those service contracts
|
|
95
|
+
and cluster requirements are appropriate.
|
|
96
|
+
|
|
97
|
+
Vector dimensions are conservatively limited to the service's 2,000-dimension
|
|
98
|
+
standard-vector contract. Azure DocumentDB also offers higher limits with
|
|
99
|
+
half-precision or product quantization; those distinct index/storage options are
|
|
100
|
+
outside this connector.
|
|
101
|
+
|
|
102
|
+
`score_threshold` uses native metric units after `$search` selects its `k`
|
|
103
|
+
candidates and before `$skip`/`$limit`. It is a minimum for cosine and inner
|
|
104
|
+
product scores, where larger is better, and a maximum for Euclidean distance,
|
|
105
|
+
where smaller is better. Set a larger `operation_options={"k": ...}` candidate
|
|
106
|
+
window when needed. Thresholded ANN search can return fewer than `top`; the
|
|
107
|
+
connector does not fetch or filter a client-side prefix. Algorithm tuning uses
|
|
108
|
+
`n_probes`, `ef_search`, or `l_search` for IVF, HNSW, or DiskANN respectively.
|
|
109
|
+
|
|
110
|
+
See the
|
|
111
|
+
[Azure DocumentDB vector search guide](https://learn.microsoft.com/azure/documentdb/vector-search),
|
|
112
|
+
[Azure DocumentDB limits](https://learn.microsoft.com/azure/documentdb/limitations),
|
|
113
|
+
[PyMongo async API](https://pymongo.readthedocs.io/en/stable/api/pymongo/asynchronous/),
|
|
114
|
+
and [Agent Framework documentation](https://learn.microsoft.com/agent-framework/).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Copyright (c) Microsoft. All rights reserved.
|
|
2
|
+
|
|
3
|
+
"""Azure DocumentDB vector collections and stores."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import importlib.metadata
|
|
8
|
+
|
|
9
|
+
from ._vector_store import AzureDocumentDBCollection, AzureDocumentDBSettings, AzureDocumentDBStore
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
__version__ = importlib.metadata.version(__name__)
|
|
13
|
+
except importlib.metadata.PackageNotFoundError:
|
|
14
|
+
__version__ = "0.0.0"
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"AzureDocumentDBCollection",
|
|
18
|
+
"AzureDocumentDBSettings",
|
|
19
|
+
"AzureDocumentDBStore",
|
|
20
|
+
"__version__",
|
|
21
|
+
]
|