SmartExtensions
Wisej.AI.SmartExtensions
Namespace: Wisej.AI
Assembly: Wisej.AI (3.5.0.0)
Provides extension methods for various operations such as calculating cosine similarity, computing clusters, converting strings to camel case, and managing services in a service provider.
public class SmartExtensions
Methods
AddOrReplaceService<TService, TImplementation>(services, lifetime)

Adds or replaces a service in the service provider with the specified implementation type.
TService
The type of service to add or replace.
TImplementation
The type of the implementation to use.
Returns: ServiceProvider. The modified service provider.
AddOrReplaceService<TService>(services, implementation, lifetime)

Adds or replaces a service in the service provider with the specified implementation instance.
TService
The type of service to add or replace.
Returns: ServiceProvider. The modified service provider.
AddOrReplaceService<TService>(services, factory, lifetime)

Adds or replaces a service in the service provider using a factory method.
TService
The type of service to add or replace.
Returns: ServiceProvider. The modified service provider.
ComputeClusters(embeddings, count, maxDivergence)

Computes clusters from the given embeddings using the K-Means clustering algorithm.
Returns: ValueTuple`2[]. An array of tuples containing the centroid and vectors of each cluster.
K-Means clustering is a method of vector quantization, originally from signal processing, that is popular for cluster analysis in data mining. This method partitions the embeddings into count clusters.
CosineSimilarity(vectorA, vectorB)

Calculates the cosine similarity between two vectors.
Returns: Single. The cosine similarity between the two vectors.
Cosine similarity is a measure of similarity between two non-zero vectors of an inner product space. It is defined as the cosine of the angle between the two vectors.
CosineSimilarity(vectorA, vectorB)

Calculates the cosine similarity between a vector and an array of vectors.
Returns: Single[]. An array of cosine similarity values for each vector in the array.
This method extends the single vector cosine similarity calculation to handle multiple vectors, returning an array of similarity scores.
ToCamelCase(text)

Converts the first character of the string to lowercase, making it camel case.
Returns: String. The camel case version of the string.
This method is useful for converting PascalCase strings to camelCase, which is often used in JSON serialization and other contexts.
Last updated