# IVectorSearchStore

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.ivectorsearchstore/
> Summary: IVectorSearchStore: The embedding-based semantic search store.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.Abstractions.dll</code></div>

The embedding-based semantic search store.

```csharp
public interface IVectorSearchStore
```

## Remarks

**There is no default implementation**. The only
concrete implementation is in `Tracon.PostgreSql` and requires the
`pgvector` extension. A SQL Server or SQLite consumer may register
their own implementation; when none is registered, `EnableVectorSearch = true`
throws an explicit error at startup instead of silently returning an empty result.

This interface does not wrap `Microsoft.Extensions.VectorData.VectorStore`.
Measured against `Microsoft.Extensions.VectorData.Abstractions` 10.8.2 —
the version the restore graph resolves, because that package is transitive
here and is named in no pin file:
`VectorSearchOptions<TRecord>.Filter` is an
`Expression<Func<TRecord,bool>>`. Translating an expression
tree breaks the AOT stance, and `Tracon.PostgreSql` is AOT-compatible.

**DI lifetime — singleton, optional.** No default
implementation is registered; `Tracon.PostgreSql` registers one
with `TryAdd` when `EnableVectorSearch = true`. A consumer's
own registration must be a singleton — a scoped registration would be a
captive dependency.

## Properties

### <a id="Tracon_IVectorSearchStore_Dimensions"></a> Dimensions

The embedding dimensionality the store expects.

```csharp
int Dimensions { get; }
```

#### Property Value

 [int](https://learn.microsoft.com/dotnet/api/system.int32)

## Methods

### <a id="Tracon_IVectorSearchStore_DeleteSourceAsync_System_String_System_String_System_String_System_Threading_CancellationToken_"></a> DeleteSourceAsync\(string, string, string, CancellationToken\)

Deletes all chunks of a source.

```csharp
ValueTask<int> DeleteSourceAsync(string tenantId, string collection, string sourceId, CancellationToken cancellationToken = default)
```

#### Parameters

`tenantId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The tenant identifier.

`collection` [string](https://learn.microsoft.com/dotnet/api/system.string)

The collection name.

`sourceId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The source identifier to delete.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[int](https://learn.microsoft.com/dotnet/api/system.int32)\>

The number of deleted chunks.

### <a id="Tracon_IVectorSearchStore_ListSourcesAsync_System_String_System_String_System_Threading_CancellationToken_"></a> ListSourcesAsync\(string, string, CancellationToken\)

Lists all source identifiers in a collection.

```csharp
ValueTask<IReadOnlyList<string>> ListSourcesAsync(string tenantId, string collection, CancellationToken cancellationToken = default)
```

#### Parameters

`tenantId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The tenant identifier.

`collection` [string](https://learn.microsoft.com/dotnet/api/system.string)

The collection name.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[IReadOnlyList](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist\-1)<[string](https://learn.microsoft.com/dotnet/api/system.string)\>\>

The source identifiers, in alphabetical order.

### <a id="Tracon_IVectorSearchStore_SearchAsync_Tracon_VectorSearchRequest_System_Threading_CancellationToken_"></a> SearchAsync\(VectorSearchRequest, CancellationToken\)

Returns the chunks nearest to the embedding.

```csharp
ValueTask<IReadOnlyList<VectorSearchHit>> SearchAsync(VectorSearchRequest request, CancellationToken cancellationToken = default)
```

#### Parameters

`request` [VectorSearchRequest](/api/tracon.vectorsearchrequest/)

The search request.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[IReadOnlyList](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist\-1)<[VectorSearchHit](/api/tracon.vectorsearchhit/)\>\>

Results ordered by ascending distance.

### <a id="Tracon_IVectorSearchStore_UpsertAsync_System_String_System_String_System_String_System_Collections_Generic_IReadOnlyList_Tracon_VectorChunk__System_Threading_CancellationToken_"></a> UpsertAsync\(string, string, string, IReadOnlyList<VectorChunk\>, CancellationToken\)

Writes chunks together with their embeddings. If the same source
(`sourceId`) is written again, the old chunks are deleted.

```csharp
ValueTask UpsertAsync(string tenantId, string collection, string sourceId, IReadOnlyList<VectorChunk> chunks, CancellationToken cancellationToken = default)
```

#### Parameters

`tenantId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The tenant identifier.

`collection` [string](https://learn.microsoft.com/dotnet/api/system.string)

The collection name.

`sourceId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The source identifier distinguishing the document.

`chunks` [IReadOnlyList](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist\-1)<[VectorChunk](/api/tracon.vectorchunk/)\>

The chunks to write.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask)

#### Exceptions

 [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)

A chunk's embedding length does not match [IVectorSearchStore.Dimensions](/api/tracon.ivectorsearchstore/#Tracon_IVectorSearchStore_Dimensions).
