# IEmbeddingStorageService

Namespace: **Wisej.AI.Services**

Assembly: **Wisej.AI** (3.5.0.0)

Represents a service for storing and querying embedded documents within specified collections.

{% tabs %}
{% tab title="C#" %}

```csharp
public interface IEmbeddingStorageService
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Interface IEmbeddingStorageService
```

{% endtab %}
{% endtabs %}

## Methods

### ![](/files/ptrKjmmRoQB76pvrIqh0) ExistsAsync(collectionName, documentName)

Asynchronously checks if a specific document exists within a collection by its name.

| Parameter          | Type                                                          | Description                                      |
| ------------------ | ------------------------------------------------------------- | ------------------------------------------------ |
| **collectionName** | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name of the collection to check.             |
| **documentName**   | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name of the document to check for existence. |

**Returns:** [Task\<Boolean>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A boolean indicating whether the document exists in the collection.

This method is used to verify the presence of a document within a collection, useful for conditional operations.\
Example usage:

```csharp

  var service = GetEmbeddingStorageService();
  bool exists = await service.ExistsAsync("myCollection", "document1");

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown if *collectionName* or *documentName* is null.

### ![](/files/ptrKjmmRoQB76pvrIqh0) QueryAsync(collectionName, query, topN, minSimilarity, filter)

Asynchronously queries a collection of embedded documents based on a vector query, returning the top K similar documents.

| Parameter                                   | Type                                                                                     | Description                                                                                |
| ------------------------------------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| **collectionName**                          | [String](https://docs.microsoft.com/dotnet/api/system.string)                            | The name of the collection to query.                                                       |
| **query**                                   | [Single\[\]](https://docs.microsoft.com/dotnet/api/system.single)                        | The query vector to compare against the stored document embeddings.                        |
| **topN**                                    | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)                              | The maximum number of similar documents to return.                                         |
| **minSimilarity**                           | [Single](https://docs.microsoft.com/dotnet/api/system.single)                            | The minimum similarity threshold for the documents to be considered relevant.              |
| **filter** ![](/files/52BqKf9SltWQ97FbQSBF) | [Predicate\<EmbeddedDocument>](https://docs.microsoft.com/dotnet/api/system.predicate-1) | An optional predicate to filter documents before similarity calculation. Defaults to null. |

**Returns:** [Task\<EmbeddedDocument\[\]>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). An array of [EmbeddedDocument](/ai/components/api/embeddings/wisej.ai.embeddings.embeddeddocument.md) that are most similar to the query vector.

This method is used to find documents that are similar to a given vector representation, which is useful in applications such as information retrieval and recommendation systems.\
Example usage:

```csharp

  var service = GetEmbeddingStorageService();
  var similarDocuments = await service.QueryAsync("myCollection", new float[] { 0.1f, 0.2f, 0.3f }, 5, 0.8f);

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown if *collectionName* or *query* is null.
* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception)\
  Thrown if *topN* is less than 1 or *minSimilarity* is not between 0 and 1.

### ![](/files/ptrKjmmRoQB76pvrIqh0) QueryAsync(collectionName, documentName, query, topN, minSimilarity)

Asynchronously queries for a specific document within a collection based on its name and a query vector.

| Parameter          | Type                                                              | Description                                                                  |
| ------------------ | ----------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| **collectionName** | [String](https://docs.microsoft.com/dotnet/api/system.string)     | The name of the collection containing the document.                          |
| **documentName**   | [String](https://docs.microsoft.com/dotnet/api/system.string)     | The name of the document to query.                                           |
| **query**          | [Single\[\]](https://docs.microsoft.com/dotnet/api/system.single) | The query vector to compare against the document's embedding.                |
| **topN**           | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)       | The maximum number of similar documents to consider.                         |
| **minSimilarity**  | [Single](https://docs.microsoft.com/dotnet/api/system.single)     | The minimum similarity threshold for the document to be considered relevant. |

**Returns:** [Task\<EmbeddedDocument>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). The [EmbeddedDocument](/ai/components/api/embeddings/wisej.ai.embeddings.embeddeddocument.md) matching the documentName and meeting the similarity criteria.

This method allows for retrieving specific documents by name and assessing their similarity based on a vector.\
Example usage:

```csharp

  var service = GetEmbeddingStorageService();
  var document = await service.QueryAsync("myCollection", "document1", new float[] { 0.1f, 0.2f, 0.3f }, 5, 0.8f);

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown if *collectionName* , *documentName* , or *query* is null.
* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception)\
  Thrown if *topN* is less than 1 or *minSimilarity* is not between 0 and 1.

### ![](/files/ptrKjmmRoQB76pvrIqh0) RemoveAsync(collectionName, filter)

Asynchronously removes documents from a collection that match a specified predicate.

| Parameter                                   | Type                                                                                     | Description                                                              |
| ------------------------------------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
| **collectionName**                          | [String](https://docs.microsoft.com/dotnet/api/system.string)                            | The name of the collection from which documents will be removed.         |
| **filter** ![](/files/52BqKf9SltWQ97FbQSBF) | [Predicate\<EmbeddedDocument>](https://docs.microsoft.com/dotnet/api/system.predicate-1) | An optional predicate to filter documents for removal. Defaults to null. |

**Returns:** [Task](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task).

This method is useful for cleaning up documents that meet specific criteria from a collection. If no filter is provided, no action is taken, and the method exits without removing any documents.\
Example usage:

```csharp

  var service = GetEmbeddingStorageService();
  await service.RemoveAsync("myCollection", doc => doc.Name.StartsWith("temp"));

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown if *collectionName* is null.

### ![](/files/ptrKjmmRoQB76pvrIqh0) RemoveAsync(collectionName, documentName)

Asynchronously removes a specific document from a collection by its name.

| Parameter          | Type                                                          | Description                                                         |
| ------------------ | ------------------------------------------------------------- | ------------------------------------------------------------------- |
| **collectionName** | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name of the collection from which the document will be removed. |
| **documentName**   | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name of the document to be removed.                             |

**Returns:** [Task](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task).

This method directly targets and removes a document by its name, making it efficient for known documents.\
Example usage:

```csharp

  var service = GetEmbeddingStorageService();
  await service.RemoveAsync("myCollection", "document1");

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown if *collectionName* or *documentName* is null.

### ![](/files/ptrKjmmRoQB76pvrIqh0) RetrieveAsync(collectionName, documentName, includeEmbedding)

Asynchronously retrieves a specific document from a collection by its name, with optional inclusion of its embedding.

| Parameter            | Type                                                            | Description                                                                        |
| -------------------- | --------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| **collectionName**   | [String](https://docs.microsoft.com/dotnet/api/system.string)   | The name of the collection to retrieve the document from.                          |
| **documentName**     | [String](https://docs.microsoft.com/dotnet/api/system.string)   | The name of the document to retrieve.                                              |
| **includeEmbedding** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean) | A boolean indicating whether to include the document's embedding in the retrieval. |

**Returns:** [Task\<EmbeddedDocument>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). The [EmbeddedDocument](/ai/components/api/embeddings/wisej.ai.embeddings.embeddeddocument.md) that matches the specified document name.

This method fetches a document by its name and optionally includes the embedding data, which can be useful for detailed inspections.\
Example usage:

```csharp

  var service = GetEmbeddingStorageService();
  var document = await service.RetrieveAsync("myCollection", "document1", false);

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown if *collectionName* or *documentName* is null.

### ![](/files/ptrKjmmRoQB76pvrIqh0) RetrieveAsync(collectionName, includeEmbedding, filter)

Asynchronously retrieves documents from a collection with optional embedding inclusion and filtering.

| Parameter                                   | Type                                                                                     | Description                                                                           |
| ------------------------------------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
| **collectionName**                          | [String](https://docs.microsoft.com/dotnet/api/system.string)                            | The name of the collection to retrieve documents from.                                |
| **includeEmbedding**                        | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)                          | A boolean indicating whether to include the embeddings of documents in the retrieval. |
| **filter** ![](/files/52BqKf9SltWQ97FbQSBF) | [Predicate\<EmbeddedDocument>](https://docs.microsoft.com/dotnet/api/system.predicate-1) | An optional predicate to filter documents for retrieval. Defaults to null.            |

**Returns:** [Task\<EmbeddedDocument\[\]>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). An array of [EmbeddedDocument](/ai/components/api/embeddings/wisej.ai.embeddings.embeddeddocument.md) that match the specified criteria.

This method retrieves documents from a collection, optionally including their embedding data, and applies an optional filter.\
Example usage:

```csharp

  var service = GetEmbeddingStorageService();
  var documents = await service.RetrieveAsync("myCollection", false, doc => doc.Name.Contains("important"));

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown if *collectionName* is null.

### ![](/files/ptrKjmmRoQB76pvrIqh0) StoreAsync(collectionName, document)

Asynchronously stores an embedded document within the specified collection.

| Parameter          | Type                                                                                      | Description                                                   |
| ------------------ | ----------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
| **collectionName** | [String](https://docs.microsoft.com/dotnet/api/system.string)                             | The name of the collection where the document will be stored. |
| **document**       | [EmbeddedDocument](/ai/components/api/embeddings/wisej.ai.embeddings.embeddeddocument.md) | The embedded document to store.                               |

**Returns:** [Task](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task).

This method is used to persist an embedded document in the specified collection, allowing it to be queried later.\
Example usage:

```csharp

  var service = GetEmbeddingStorageService();
  await service.StoreAsync("myCollection", new EmbeddedDocument("newDocument"));

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown if *collectionName* or *document* is null.

## Implemented By

| Name                                                                                                                                                   | Description                                                                                                                                       |
| ------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| [AzureAISearchEmbeddingStorageService](/ai/components/api/services/iembeddingstorageservice/wisej.ai.services.azureaisearchembeddingstorageservice.md) | Represents a service for storing and querying embeddings using Azure AI Search.                                                                   |
| [ChromaEmbeddingStorageService](/ai/components/api/services/iembeddingstorageservice/wisej.ai.services.chromaembeddingstorageservice.md)               | Represents a service for storing and retrieving embeddings using Chroma.                                                                          |
| [FileSystemEmbeddingStorageService](https://docs.wisej.com/api?q=wisej.ai.services.filesystemembeddingstorageservice)                                  | Provides a file system-based implementation of the [IEmbeddingStorageService](/ai/components/api/services/iembeddingstorageservice.md) interface. |
| [MemoryEmbeddingStorageService](https://docs.wisej.com/api?q=wisej.ai.services.memoryembeddingstorageservice)                                          | Provides an in-memory implementation of the [IEmbeddingStorageService](/ai/components/api/services/iembeddingstorageservice.md) interface.        |
| [PineconeEmbeddingStorageService](/ai/components/api/services/iembeddingstorageservice/wisej.ai.services.pineconeembeddingstorageservice.md)           | Represents a service for storing and retrieving embeddings using Pinecone.                                                                        |
| [QdrantEmbeddingStorageService](/ai/components/api/services/iembeddingstorageservice/wisej.ai.services.qdrantembeddingstorageservice.md)               | Represents a service for storing and retrieving embeddings using Qdrant.                                                                          |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/ai/components/api/services/iembeddingstorageservice.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
