# SmartHub

Namespace: **Wisej.AI**

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

* [SmartObject](/ai/components/api/wisej.ai.smartobject.md)
  * [SmartHub](/ai/components/api/smarthub.md)

Represents a SmartHub component that provides AI capabilities to controls within a container.

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

```csharp
public class SmartHub : SmartObject, IExtenderProvider, IToolProvider
```

{% endtab %}

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

```visual-basic
Public Class SmartHub
    Inherits SmartObject
    Implements IExtenderProvider, IToolProvider
```

{% endtab %}
{% endtabs %}

The SmartHub class is an extender provider that allows controls to be extended with AI functionalities. It manages various services and tools to facilitate AI operations, such as embedding generation, document conversion, and similarity queries.

## Constructors

### ![](/files/ptrKjmmRoQB76pvrIqh0) SmartHub()

Initializes a new instance of the [SmartHub](/ai/components/api/smarthub.md) class.

### ![](/files/ptrKjmmRoQB76pvrIqh0) SmartHub(containerControl)

Initializes a new instance of the [SmartHub](/ai/components/api/smarthub.md) class with a specified container control.

| Name                 | Type                                                                        | Description                                              |
| -------------------- | --------------------------------------------------------------------------- | -------------------------------------------------------- |
| **containerControl** | [ContainerControl](https://docs.wisej.com/api?q=wisej.web.containercontrol) | The container control to which the SmartHub is attached. |

**Throws:**

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

### ![](/files/ptrKjmmRoQB76pvrIqh0) SmartHub(container)

Initializes a new instance of the [SmartHub](/ai/components/api/smarthub.md) class attached to an [IContainer](https://docs.microsoft.com/dotnet/api/system.componentmodel.icontainer) implementation.

| Name          | Type                                                                                 | Description                                                                                                                                                                       |
| ------------- | ------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **container** | [IContainer](https://docs.microsoft.com/dotnet/api/system.componentmodel.icontainer) | An [IContainer](https://docs.microsoft.com/dotnet/api/system.componentmodel.icontainer) that represents the container of the [SmartHub](/ai/components/api/smarthub.md) extender. |

## Properties

### ![](/files/ptrKjmmRoQB76pvrIqh0) BindingContext

[BindingContext](https://docs.wisej.com/api?q=wisej.web.bindingcontext): Gets the binding context for the SmartHub.

### ![](/files/ptrKjmmRoQB76pvrIqh0) ContainerControl

[Control](https://docs.wisej.com/api?q=wisej.web.control): Returns or sets the container [Control](https://docs.wisej.com/api?q=wisej.web.control)that provides the [BindingContext](#bindingcontext) for binding to the [IDataErrorInfo](https://docs.microsoft.com/dotnet/api/system.componentmodel.idataerrorinfo) interface implemented by a [DataSource](#datasource). (Default: `null`)

### ![](/files/ptrKjmmRoQB76pvrIqh0) Culture

[CultureInfo](https://docs.microsoft.com/dotnet/api/system.globalization.cultureinfo): Gets or sets the culture information for the SmartHub. (Default: `null`)

### ![](/files/ptrKjmmRoQB76pvrIqh0) DataSource

[Object](https://docs.microsoft.com/dotnet/api/system.object): Gets or sets a data source that can be used to resolve prompt parameters. (Default: `null`)

### ![](/files/ptrKjmmRoQB76pvrIqh0) Endpoint

[SmartEndpoint](/ai/components/api/smartendpoint.md): Gets or sets the default endpoint. (Default: `null`)

### ![](/files/ptrKjmmRoQB76pvrIqh0) IsDisposed

[Boolean](https://docs.microsoft.com/dotnet/api/system.boolean): Gets a value indicating whether the SmartHub is disposed.

## Methods

### ![](/files/ptrKjmmRoQB76pvrIqh0) AskAsync(question, image, systemPrompt)

Asynchronously asks a question and returns a response message.

| Parameter                                         | Type                                                                | Description                                                      |
| ------------------------------------------------- | ------------------------------------------------------------------- | ---------------------------------------------------------------- |
| **question**                                      | [String](https://docs.microsoft.com/dotnet/api/system.string)       | The question to ask.                                             |
| **image** ![](/files/52BqKf9SltWQ97FbQSBF)        | [Image](https://docs.microsoft.com/dotnet/api/system.drawing.image) | An optional image to include in the question. Default is `null`. |
| **systemPrompt** ![](/files/52BqKf9SltWQ97FbQSBF) | [String](https://docs.microsoft.com/dotnet/api/system.string)       | Option system prompt.                                            |

**Returns:** [Task\<Message>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task representing the asynchronous operation, with a [Message](/ai/components/api/smartsession/wisej.ai.smartsession.message.md) as the result.

**Throws:**

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

### ![](/files/KL0Ik37djZRr8a07Wopd) Dispose(disposing)

Releases the unmanaged resources used by the [SmartHub](/ai/components/api/smarthub.md) and optionally releases the managed resources.

| Parameter     | Type                                                            | Description                                                                                      |
| ------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| **disposing** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean) | true to release both managed and unmanaged resources; false to release only unmanaged resources. |

### ![](/files/ptrKjmmRoQB76pvrIqh0) EmbedAsync(text)

Asynchronously generates an embedding for a specified text.

| Parameter | Type                                                          | Description        |
| --------- | ------------------------------------------------------------- | ------------------ |
| **text**  | [String](https://docs.microsoft.com/dotnet/api/system.string) | The text to embed. |

**Returns:** [Task\<Embedding>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task representing the asynchronous operation, with an [Embedding](/ai/components/api/embeddings/wisej.ai.embeddings.embedding.md) as the result.

### ![](/files/ptrKjmmRoQB76pvrIqh0) EmbedAsync(chunks)

Asynchronously generates an embedding for a specified array of text chunks.

| Parameter  | Type                                                              | Description               |
| ---------- | ----------------------------------------------------------------- | ------------------------- |
| **chunks** | [String\[\]](https://docs.microsoft.com/dotnet/api/system.string) | The text chunks to embed. |

**Returns:** [Task\<Embedding>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task representing the asynchronous operation, with an [Embedding](/ai/components/api/embeddings/wisej.ai.embeddings.embedding.md) as the result.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when the chunks array is null.

### ![](/files/ptrKjmmRoQB76pvrIqh0) GetAdapter(control)

Gets the adapter associated with a specified control.

| Parameter   | Type                                                      | Description                               |
| ----------- | --------------------------------------------------------- | ----------------------------------------- |
| **control** | [Control](https://docs.wisej.com/api?q=wisej.web.control) | The control for which to get the adapter. |

**Returns:** [SmartAdapter](/ai/components/api/smartadapter.md). The [SmartAdapter](/ai/components/api/smartadapter.md) associated with the control, or null if none exists.

**Throws:**

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

### ![](/files/ptrKjmmRoQB76pvrIqh0) GetAdapter\<T>(control)

Gets the adapter of a specified type associated with a specified control.

| Parameter   | Type                                                      | Description                               |
| ----------- | --------------------------------------------------------- | ----------------------------------------- |
| **T**       |                                                           | The type of the adapter.                  |
| **control** | [Control](https://docs.wisej.com/api?q=wisej.web.control) | The control for which to get the adapter. |

**Returns:** [T](/ai/components/api/smarthub.md). The adapter of type *T* associated with the control, or null if none exists.

**Throws:**

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

### ![](/files/ptrKjmmRoQB76pvrIqh0) GetAI(control)

Gets the AI properties for a specified control.

| Parameter   | Type                                                      | Description                                     |
| ----------- | --------------------------------------------------------- | ----------------------------------------------- |
| **control** | [Control](https://docs.wisej.com/api?q=wisej.web.control) | The control for which to get the AI properties. |

**Returns:** [Properties](https://docs.wisej.com/api?q=wisej.ai.smarthub+properties). The [Properties](https://docs.wisej.com/api?q=wisej.ai.smarthub.properties) associated with the control.

### ![](/files/ptrKjmmRoQB76pvrIqh0) GetParameterValue(parameter)

Gets the value of a specified parameter.

| Parameter     | Type                                                                          | Description                               |
| ------------- | ----------------------------------------------------------------------------- | ----------------------------------------- |
| **parameter** | [Parameter](/ai/components/api/smartprompt/wisej.ai.smartprompt.parameter.md) | The parameter for which to get the value. |

**Returns:** [Object](https://docs.microsoft.com/dotnet/api/system.object). The value of the parameter as a string.

**Throws:**

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

### ![](/files/ptrKjmmRoQB76pvrIqh0) IngestDocumentAsync(filePath, documentName, collectionName, metadata, overwrite)

Asynchronously ingests a document from a specified file path.

| Parameter                                           | Type                                                                      | Description                                                  |
| --------------------------------------------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------ |
| **filePath**                                        | [String](https://docs.microsoft.com/dotnet/api/system.string)             | The file path of the document to ingest.                     |
| **documentName**                                    | [String](https://docs.microsoft.com/dotnet/api/system.string)             | The name of the document.                                    |
| **collectionName** ![](/files/52BqKf9SltWQ97FbQSBF) | [String](https://docs.microsoft.com/dotnet/api/system.string)             | The name of the collection. Default is null.                 |
| **metadata** ![](/files/52BqKf9SltWQ97FbQSBF)       | [Metadata](/ai/components/api/embeddings/wisej.ai.embeddings.metadata.md) | The metadata for the document. Default is null.              |
| **overwrite** ![](/files/52BqKf9SltWQ97FbQSBF)      | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)           | Whether to overwrite an existing document. Default is false. |

**Returns:** [Task\<EmbeddedDocument>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task representing the asynchronous operation, with an [EmbeddedDocument](/ai/components/api/embeddings/wisej.ai.embeddings.embeddeddocument.md) as the result.

This method utilizes several services to perform its operations: [ITextSplitterService](/ai/components/api/services/itextsplitterservice.md), and [IDocumentConversionService](/ai/components/api/services/idocumentconversionservice.md), and [IEmbeddingGenerationService](/ai/components/api/services/iembeddinggenerationservice.md), and [IEmbeddingStorageService](/ai/components/api/services/iembeddingstorageservice.md).**Throws:**

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

### ![](/files/ptrKjmmRoQB76pvrIqh0) IngestDocumentAsync(stream, documentName, collectionName, overwrite, metadata)

Asynchronously ingests a document from a specified stream.

| Parameter                                           | Type                                                                      | Description                                                  |
| --------------------------------------------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------ |
| **stream**                                          | [Stream](https://docs.microsoft.com/dotnet/api/system.io.stream)          | The stream of the document to ingest.                        |
| **documentName**                                    | [String](https://docs.microsoft.com/dotnet/api/system.string)             | The name of the document.                                    |
| **collectionName** ![](/files/52BqKf9SltWQ97FbQSBF) | [String](https://docs.microsoft.com/dotnet/api/system.string)             | The name of the collection. Default is null.                 |
| **overwrite** ![](/files/52BqKf9SltWQ97FbQSBF)      | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)           | Whether to overwrite an existing document. Default is false. |
| **metadata** ![](/files/52BqKf9SltWQ97FbQSBF)       | [Metadata](/ai/components/api/embeddings/wisej.ai.embeddings.metadata.md) | The metadata for the document. Default is null.              |

**Returns:** [Task\<EmbeddedDocument>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task representing the asynchronous operation, with an [EmbeddedDocument](/ai/components/api/embeddings/wisej.ai.embeddings.embeddeddocument.md) as the result.

This method utilizes several services to perform its operations: [ITextSplitterService](/ai/components/api/services/itextsplitterservice.md), and [IDocumentConversionService](/ai/components/api/services/idocumentconversionservice.md), and [IEmbeddingGenerationService](/ai/components/api/services/iembeddinggenerationservice.md), and [IEmbeddingStorageService](/ai/components/api/services/iembeddingstorageservice.md).**Throws:**

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

### ![](/files/ptrKjmmRoQB76pvrIqh0) RemoveAdapter(adapter)

Removes a specified adapter from the SmartHub.

| Parameter   | Type                                               | Description            |
| ----------- | -------------------------------------------------- | ---------------------- |
| **adapter** | [SmartAdapter](/ai/components/api/smartadapter.md) | The adapter to remove. |

**Throws:**

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

### ![](/files/ptrKjmmRoQB76pvrIqh0) RemoveTool(tool)

Removes a tool from the SmartHub.

| Parameter | Type                                                              | Description         |
| --------- | ----------------------------------------------------------------- | ------------------- |
| **tool**  | [Delegate](https://docs.microsoft.com/dotnet/api/system.delegate) | The tool to remove. |

**Returns:** [SmartHub](/ai/components/api/smarthub.md). The current [SmartHub](/ai/components/api/smarthub.md) instance.

**Throws:**

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

### ![](/files/ptrKjmmRoQB76pvrIqh0) SimilarityQueryAsync(query, chunks, topN, minSimilarity, computeSimilarity)

Asynchronously performs a similarity query on a specified query and text chunks.

| Parameter                                              | Type                                                                                                 | Description                                          |
| ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| **query**                                              | [String](https://docs.microsoft.com/dotnet/api/system.string)                                        | The query text.                                      |
| **chunks**                                             | [String\[\]](https://docs.microsoft.com/dotnet/api/system.string)                                    | The text chunks to compare against.                  |
| **topN**                                               | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)                                          | The number of top results to return.                 |
| **minSimilarity**                                      | [Single](https://docs.microsoft.com/dotnet/api/system.single)                                        | The minimum similarity threshold.                    |
| **computeSimilarity** ![](/files/52BqKf9SltWQ97FbQSBF) | [Func\<Single\[\], Single\[\]\[\], Single\[\]>](https://docs.microsoft.com/dotnet/api/system.func-3) | The function to compute similarity. Default is null. |

**Returns:** [Task\<String\[\]>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task representing the asynchronous operation, with an array of strings as the result.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when the query or chunks are null.

### ![](/files/ptrKjmmRoQB76pvrIqh0) SimilarityQueryAsync(query, chunks, vectors, topN, minSimilarity, computeSimilarity)

Asynchronously performs a similarity query on a specified query, text chunks, and vectors.

| Parameter                                              | Type                                                                                                 | Description                                          |
| ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| **query**                                              | [String](https://docs.microsoft.com/dotnet/api/system.string)                                        | The query text.                                      |
| **chunks**                                             | [String\[\]](https://docs.microsoft.com/dotnet/api/system.string)                                    | The text chunks to compare against.                  |
| **vectors**                                            | [Single\[\]\[\]](https://docs.microsoft.com/dotnet/api/system.single)                                | The vectors to compare against.                      |
| **topN**                                               | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)                                          | The number of top results to return.                 |
| **minSimilarity**                                      | [Single](https://docs.microsoft.com/dotnet/api/system.single)                                        | The minimum similarity threshold.                    |
| **computeSimilarity** ![](/files/52BqKf9SltWQ97FbQSBF) | [Func\<Single\[\], Single\[\]\[\], Single\[\]>](https://docs.microsoft.com/dotnet/api/system.func-3) | The function to compute similarity. Default is null. |

**Returns:** [Task\<String\[\]>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task representing the asynchronous operation, with an array of strings as the result.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when the query, chunks, or vectors are null.

### ![](/files/ptrKjmmRoQB76pvrIqh0) SimilarityScoreAsync(query, chunks, computeSimilarity)

Asynchronously calculates similarity scores for a specified query and text chunks.

| Parameter                                              | Type                                                                                                 | Description                                          |
| ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| **query**                                              | [String](https://docs.microsoft.com/dotnet/api/system.string)                                        | The query text.                                      |
| **chunks**                                             | [String\[\]](https://docs.microsoft.com/dotnet/api/system.string)                                    | The text chunks to compare against.                  |
| **computeSimilarity** ![](/files/52BqKf9SltWQ97FbQSBF) | [Func\<Single\[\], Single\[\]\[\], Single\[\]>](https://docs.microsoft.com/dotnet/api/system.func-3) | The function to compute similarity. Default is null. |

**Returns:** [Task\<Single\[\]>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task representing the asynchronous operation, with an array of floats as the result.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when the query or chunks are null.

### ![](/files/ptrKjmmRoQB76pvrIqh0) SimilarityScoreAsync(query, chunks, embeddings, computeSimilarity)

Asynchronously calculates similarity scores for a specified query, text chunks, and embeddings.

| Parameter                                              | Type                                                                                                 | Description                                          |
| ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| **query**                                              | [String](https://docs.microsoft.com/dotnet/api/system.string)                                        | The query text.                                      |
| **chunks**                                             | [String\[\]](https://docs.microsoft.com/dotnet/api/system.string)                                    | The text chunks to compare against.                  |
| **embeddings**                                         | [Single\[\]\[\]](https://docs.microsoft.com/dotnet/api/system.single)                                | The embeddings to compare against.                   |
| **computeSimilarity** ![](/files/52BqKf9SltWQ97FbQSBF) | [Func\<Single\[\], Single\[\]\[\], Single\[\]>](https://docs.microsoft.com/dotnet/api/system.func-3) | The function to compute similarity. Default is null. |

**Returns:** [Task\<Single\[\]>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task representing the asynchronous operation, with an array of floats as the result.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when the query, chunks, or embeddings are null.

### ![](/files/ptrKjmmRoQB76pvrIqh0) UseTool(tool)

Adds a tool to the SmartHub.

| Parameter | Type                                                              | Description      |
| --------- | ----------------------------------------------------------------- | ---------------- |
| **tool**  | [Delegate](https://docs.microsoft.com/dotnet/api/system.delegate) | The tool to add. |

**Returns:** [SmartHub](/ai/components/api/smarthub.md). The current [SmartHub](/ai/components/api/smarthub.md) instance.

**Throws:**

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

### ![](/files/ptrKjmmRoQB76pvrIqh0) UseTools(target)

Uses tools from a specified target.

| Parameter  | Type                                                          | Description                         |
| ---------- | ------------------------------------------------------------- | ----------------------------------- |
| **target** | [Object](https://docs.microsoft.com/dotnet/api/system.object) | The target from which to use tools. |

**Returns:** [SmartHub](/ai/components/api/smarthub.md). The current [SmartHub](/ai/components/api/smarthub.md) instance.

## Implements

| Name                                                                              | Description                                |
| --------------------------------------------------------------------------------- | ------------------------------------------ |
| [IToolProvider](/ai/components/api/smarttool/wisej.ai.smarttool.itoolprovider.md) | Represents a provider that supplies tools. |


---

# 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/smarthub.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.
