# HuggingFaceEmbeddingGenerationService

Namespace: **Wisej.AI.Services**

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

Represents a service for generating embeddings using the Hugging Face API.

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

```csharp
public class HuggingFaceEmbeddingGenerationService : IEmbeddingGenerationService
```

{% endtab %}

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

```visual-basic
Public Class HuggingFaceEmbeddingGenerationService
    Inherits IEmbeddingGenerationService
```

{% endtab %}
{% endtabs %}

This class implements the [IEmbeddingGenerationService](https://docs.wisej.com/ai/components/api/services/iembeddinggenerationservice) interface and provides methods to generate embeddings from text chunks using the Hugging Face API.

## Constructors

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FdLVsGEp1mKmjdHvG0Itk%2Finstance.png?alt=media\&token=0061ee96-c913-420d-aa2f-daf782ca6a1d) HuggingFaceEmbeddingGenerationService(url)

Initializes a new instance of the [HuggingFaceEmbeddingGenerationService](https://docs.wisej.com/ai/components/api/services/iembeddinggenerationservice/wisej.ai.services.huggingfaceembeddinggenerationservice) class with an optional URL.

| Name    | Type                                                          | Description                                              |
| ------- | ------------------------------------------------------------- | -------------------------------------------------------- |
| **url** | [String](https://docs.microsoft.com/dotnet/api/system.string) | The base URL of the Hugging Face API. Default is `null`. |

## Properties

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FdLVsGEp1mKmjdHvG0Itk%2Finstance.png?alt=media\&token=0061ee96-c913-420d-aa2f-daf782ca6a1d) MaxArraySize

[Int32](https://docs.microsoft.com/dotnet/api/system.int32): Gets or sets the maximum size of the array that can be processed in a single request. (Default: `100`)

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FdLVsGEp1mKmjdHvG0Itk%2Finstance.png?alt=media\&token=0061ee96-c913-420d-aa2f-daf782ca6a1d) URL

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets or sets the base URL of the Hugging Face API. (Default: `null`)

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FdLVsGEp1mKmjdHvG0Itk%2Finstance.png?alt=media\&token=0061ee96-c913-420d-aa2f-daf782ca6a1d) VectorSize

[Int32](https://docs.microsoft.com/dotnet/api/system.int32): Gets or sets the size of the vector for the embeddings. This property is not used. (Default: `0`)

## Methods

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FdLVsGEp1mKmjdHvG0Itk%2Finstance.png?alt=media\&token=0061ee96-c913-420d-aa2f-daf782ca6a1d) EmbedAsync(chunks)

Asynchronously generates embeddings for the provided text chunks.

| Parameter  | Type                                                              | Description                                         |
| ---------- | ----------------------------------------------------------------- | --------------------------------------------------- |
| **chunks** | [String\[\]](https://docs.microsoft.com/dotnet/api/system.string) | An array of text chunks to generate embeddings for. |

**Returns:** [Task\<Embedding>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task that represents the asynchronous operation. The task result contains the generated [Embedding](https://docs.wisej.com/ai/components/api/embeddings/wisej.ai.embeddings.embedding).

This method handles chunking of input data and parallelizes requests if necessary. It combines results from multiple requests if the input exceeds the maximum array size.

```csharp

var service = new HuggingFaceEmbeddingGenerationService("http://api.example.com");
var embedding = await service.EmbedAsync(new string[] { "text1", "text2" });

```

## Implements

| Name                                                                                                         | Description                                                                      |
| ------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- |
| [IEmbeddingGenerationService](https://docs.wisej.com/ai/components/api/services/iembeddinggenerationservice) | Represents a service capable of generating embeddings from provided text chunks. |


---

# 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/iembeddinggenerationservice/wisej.ai.services.huggingfaceembeddinggenerationservice.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.
