Bemærk
Adgang til denne side kræver godkendelse. Du kan prøve at logge på eller ændre mapper.
Adgang til denne side kræver godkendelse. Du kan prøve at ændre mapper.
Vector stores keep data and its vector embeddings together so applications can find records by semantic similarity. In Agent Framework applications, you can use vector stores to retrieve grounding data for Retrieval Augmented Generation (RAG) or to store information that an agent can recall later.
Vector store abstractions provide common operations for collections and records, keeping your application logic separated from the specific vector store implementation. You can, for example, start with a local implementation and switch to a managed service with minimal changes.
How vector store integrations work
A typical vector store workflow includes these steps:
- Define a data model that identifies the record key, data fields, and vector fields.
- Configure an embedding generator if the vector store doesn't generate embeddings.
- Connect to a vector store and select or create a collection.
- Generate embeddings and upsert records into the collection.
- Search the collection with text or a vector, depending on the implementation's capabilities.
- Pass relevant search results to an agent as context or expose search as an agent tool.
.NET vector store support
Agent Framework uses the .NET AI ecosystem's standalone abstractions:
Microsoft.Extensions.VectorDataprovides common vector store, collection, record, and search APIs.Microsoft.Extensions.AIprovides abstractions such asIEmbeddingGeneratorfor generating embeddings independently of a specific model provider.
Where an Agent Framework component accepts a vector store, you can supply a
compatible Microsoft.Extensions.VectorData implementation. Each database
implementation is distributed separately from the abstractions package.
Core abstractions
| Abstraction | Purpose |
|---|---|
VectorStore |
Provides operations across collections and creates typed collection instances. |
VectorStoreCollection<TKey, TRecord> |
Creates or deletes a collection and upserts, retrieves, or deletes its records. |
IVectorSearchable<TRecord> |
Searches records by vector or by text when an embedding generator or database-side embedding capability is available. |
Available vector store implementations
The following implementations use the common .NET vector store abstractions. Review each implementation's documentation for package versions, supported data types, and service-specific limitations.
| Implementation | Availability | Uses an officially supported database SDK | Maintainer or vendor |
|---|---|---|---|
| Azure AI Search | Available | Yes | Microsoft |
| Azure Cosmos DB for MongoDB vCore | Available | Yes | Microsoft |
| Azure Cosmos DB for NoSQL | Available | Yes | Microsoft |
| Couchbase | Available | Yes | Couchbase |
| Elasticsearch | Available | Yes | Elastic |
| Chroma | Planned | Not applicable | Not applicable |
| In-memory | Available | Not applicable | Microsoft |
| Milvus | Planned | Not applicable | Not applicable |
| MongoDB | Available | Yes | Microsoft |
| Neon Serverless Postgres | Use the Postgres implementation | Yes | Microsoft |
| Oracle | Available | Yes | Oracle |
| Pinecone | Available | No | Microsoft |
| Postgres | Available | Yes | Microsoft |
| Qdrant | Available | Yes | Microsoft |
| Redis | Available | Yes | Microsoft |
| SQL Server | Available | Yes | Microsoft |
| SQLite | Available | Yes | Microsoft |
| Volatile in-memory | Deprecated; use the in-memory implementation | Not applicable | Microsoft |
| Weaviate | Available | Yes | Microsoft |
Important
Vector store implementations come from multiple maintainers. Evaluate each implementation's quality, licensing, support policy, and version compatibility before you use it. Some implementations use database SDKs that the database provider doesn't officially support.
Get started
- Add the
Microsoft.Extensions.VectorData.Abstractionspackage and the package for your chosen vector store implementation. - Define a record type and identify its key, data, and vector properties.
- Configure an
IEmbeddingGeneratorif your implementation requires application-generated embeddings. - Create the implementation's
VectorStore, and then get a typedVectorStoreCollection<TKey, TRecord>. - Ensure that the collection exists, upsert records, and call
SearchAsyncwith text or a vector.
For a complete introduction to data models, ingestion, embeddings, and search, see Vector databases for .NET AI apps.
Python vector store support
Agent Framework provides experimental, native Python contracts for vector store
models, collection operations, store factories, vector and keyword-hybrid
search, and agent search tools. The contracts are part of
agent-framework-core and don't require Pydantic, NumPy, pandas, or Semantic
Kernel.
Warning
The native Python vector store APIs are experimental. Limited breaking changes might occur before they become stable.
Core abstractions
| Abstraction | Purpose |
|---|---|
VectorStoreField and VectorStoreCollectionDefinition |
Describe key, data, and vector fields, including storage names, indexes, dimensions, and distance functions. |
@vectorstoremodel and register_vectorstoremodel() |
Register dataclasses, Pydantic models, msgspec structs, plain classes, or externally owned model types. |
BaseVectorCollection and SupportsVectorUpsert |
Define batch upsert, get, delete, collection lifecycle, record conversion, and optional embedding generation. |
BaseVectorStore |
Defines a store that lists collections and creates typed collection clients. |
BaseVectorSearch and SupportsVectorSearch |
Define vector and keyword-hybrid search, paging, filters, score thresholds, and search results. |
Filter, FilterGroup, and Param |
Define portable, data-only filters, including model-supplied filter parameters for search tools. |
InMemoryStore and InMemoryCollection |
Provide process-local CRUD and linear-scan search for development and tests. |
GenerateVectors |
Controls whether upserts generate all, none, or selected vector fields. |
create_vector_search_tool() |
Exposes any SupportsVectorSearch implementation as an Agent Framework function tool. |
The following sample defines vector store records by annotating their key, data, and vector fields:
# 5. Dataclasses use the default registered codec.
@vectorstoremodel(collection_name="hotels")
@dataclass
class Hotel:
hotel_id: Annotated[str, VectorStoreField("key")]
name: Annotated[str, VectorStoreField("data", is_indexed=True)]
description: Annotated[
str | list[float] | None,
VectorStoreField("vector", dimensions=3, distance_function="cosine_similarity"),
] = None
# 6. Pydantic models provide validation with additional round-trip cost.
@vectorstoremodel(collection_name="products")
class Product(BaseModel):
product_id: Annotated[str, VectorStoreField("key")]
name: Annotated[str, VectorStoreField("data", is_full_text_indexed=True)]
vector: Annotated[list[float] | None, VectorStoreField("vector", dimensions=3)] = None
Use VectorStoreCollectionDefinition directly for dictionaries. For model types
owned by another package, use register_vectorstoremodel() with an explicit
definition and optional encoder and decoder. Array-like vector values serialize
through tolist() without adding a NumPy dependency.
Agent Framework includes an in-memory implementation for development and tests. It stores records in the current process and uses a linear scan, so use a database connector for production workloads.
The following sample stores precomputed vectors and searches them with a portable filter tree:
import asyncio
from dataclasses import dataclass
from typing import Annotated
from agent_framework import Filter, FilterGroup, InMemoryCollection, VectorStoreField, vectorstoremodel
@vectorstoremodel(collection_name="hotels")
@dataclass
class Hotel:
hotel_id: Annotated[str, VectorStoreField("key")]
name: Annotated[str, VectorStoreField("data")]
city: Annotated[str, VectorStoreField("data")]
rating: Annotated[float, VectorStoreField("data")]
amenities: Annotated[list[str], VectorStoreField("data")]
vector: Annotated[
list[float] | None,
VectorStoreField("vector", dimensions=2, distance_function="cosine_similarity"),
] = None
async def main() -> None:
"""Store precomputed vectors and search them with direct filters."""
collection: InMemoryCollection[str, Hotel] = InMemoryCollection(Hotel)
await collection.ensure_collection_exists()
# 1. The sample already has vectors, so generation is disabled explicitly.
await collection.upsert(
[
Hotel("hotel-1", "Harbor View", "Lisbon", 4.8, ["wifi", "pool"], [1.0, 0.1]),
Hotel("hotel-2", "Old Town Rooms", "Lisbon", 4.1, ["wifi"], [0.8, 0.2]),
Hotel("hotel-3", "City Center", "Seattle", 4.7, ["wifi", "gym"], [0.1, 1.0]),
],
generate_vectors=False,
)
# 2. Filter values are ordinary data. No Python source is parsed or executed.
search_filter = FilterGroup(
"and",
(
Filter("city", "eq", "Lisbon"),
Filter("rating", "between", (4.5, 5.0)),
Filter("amenities", "contains", "pool"),
),
)
results = await collection.search(
vector=[1.0, 0.0],
filter=search_filter,
top=5,
)
# 3. Search results are consumed asynchronously.
async for result in results:
print(f"{result['record'].name}: {result['score']:.3f}")
Use Param when the model should supply a filter value. Its Python type,
description, and constraints become part of the search tool's JSON schema:
# 2. Param values become optional model-visible filter arguments.
# When the allowed values are known, use Literal so the tool schema exposes
# them as an enum.
category = Param(
"category",
Literal["Boutique", "Budget", "Extended-Stay", "Luxury", "Resort and Spa", "Suite"],
description="Only return hotels in this category.",
)
min_rating = Param(
"min_rating",
float,
description="The minimum guest rating.",
minimum=0,
maximum=5,
)
tool = create_vector_search_tool(
collection,
description="Search the hotel dataset, optionally filtering by category and minimum rating.",
filter=FilterGroup(
"and",
(
Filter("category", "eq", category),
Filter("rating", "gte", min_rating),
),
),
result_mapper=lambda result: (
f"(hotel_id: {result['record'].hotel_id}) {result['record'].hotel_name} "
f"(rating {result['record'].rating}) - {result['record'].description}. "
f"Address: {result['record'].address.city}, {result['record'].address.country}."
),
)
Native Agent Framework implementations
The following implementations use the native Agent Framework contracts. Each one is also available as a separate Semantic Kernel connector, but the two connector families aren't interchangeable.
| Implementation | Agent Framework package and lifecycle | Separate Semantic Kernel connector | Search modes | Key limitations |
|---|---|---|---|---|
| In-memory | agent-framework-core; released package with experimental vector APIs |
Available | Dense vector with portable filters | Process-local linear scan for development and tests, not a production database. |
| Azure AI Search | agent-framework-azure-ai-search; beta package with experimental vector APIs |
Available | Dense vector and keyword-hybrid | One top-level dense vector field per query. Some thresholds, hybrid text-recall controls, strict post-filtering, and permissions require a supporting preview SDK/API and allow_preview=True. |
| PostgreSQL with pgvector | agent-framework-postgres; alpha package |
Available | Exact dense vector, HNSW, and IVFFlat | Requires PostgreSQL 13+, pgvector 0.8.0+, an existing schema, and the enabled extension. Keyword and hybrid search aren't supported. |
| Qdrant | agent-framework-qdrant; alpha package |
Available | Dense vector with server-side portable filters | Server mode requires Qdrant 1.16.2+. Keys must be unsigned 64-bit integers or UUIDs. Keyword and hybrid search aren't supported, and filters aren't available in local SDK mode. |
| Redis | agent-framework-redis; beta package with experimental vector APIs |
Available | Dense vector over HASH or JSON records | Requires Redis 8.0.3+ with Search; JSON records also require RedisJSON. Redis Cluster, keyword search, and hybrid search aren't supported. |
Install a prerelease connector package for the database you use:
pip install agent-framework-azure-ai-search --pre
pip install agent-framework-postgres --pre
pip install agent-framework-qdrant --pre
pip install agent-framework-redis --pre
Each connector implements the common model, collection, CRUD, filter, and search contracts. Database-specific capabilities and restrictions still apply. For complete examples, see the Azure AI Search, Postgres, Qdrant, and Redis samples.
Semantic Kernel-only implementations
Applications can continue to use Semantic Kernel's Python vector stores directly. These implementations use the separate Semantic Kernel vector store contracts rather than the native Agent Framework contracts. The following implementations don't currently have a native Agent Framework connector:
| Implementation | Availability | Uses an officially supported database SDK | Maintainer or vendor |
|---|---|---|---|
| Azure Cosmos DB for MongoDB vCore | Available | Yes | Microsoft Semantic Kernel project |
| Azure Cosmos DB for NoSQL | Available | Yes | Microsoft Semantic Kernel project |
| Chroma | Available | Yes | Microsoft Semantic Kernel project |
| Elasticsearch | Planned | Not applicable | Not applicable |
| Faiss | Available | Yes | Microsoft Semantic Kernel project |
| MongoDB | Available | Yes | Microsoft Semantic Kernel project |
| Neon Serverless Postgres | Use the Postgres implementation | Yes | Microsoft Semantic Kernel project |
| Oracle | Available | Yes | Oracle |
| Pinecone | Available | Yes | Microsoft Semantic Kernel project |
| SQL Server | Available | pyodbc |
Microsoft Semantic Kernel project |
| SQLite | Planned | Not applicable | Microsoft Semantic Kernel project |
| Weaviate | Available | Yes | Microsoft Semantic Kernel project |
Important
Vector store implementations come from multiple maintainers. Evaluate each implementation's quality, licensing, support policy, and version compatibility before you use it.
Use a Semantic Kernel-only implementation
- Install
semantic-kerneland the dependencies required by your chosen implementation. - Define a model with the
@vectorstoremodeldecorator and identify its key, data, and vector fields. - Create an implementation-specific collection for that model.
- Ensure that the collection exists, and then upsert records.
- Use the collection's search APIs to retrieve records for your application.
For implementation setup and complete examples, see Semantic Kernel Vector Stores.
Go vector store support
Vector store integration isn't yet available in Agent Framework for Go. See the Agent Framework Go repository for the latest status.