BGE<T>

Models & Types · AiDotNet.NeuralNetworks

BGE (BAAI General Embedding) neural network implementation. A state-of-the-art retrieval model known for its high accuracy across diverse benchmarks.

Inheritance: NeuralNetworkBase<T> → DeclaredModelLayoutBase<T> → TextEmbeddingModelLayoutBase<T> → TransformerEmbeddingNetwork<T> → BGE<T>

For Beginners

BGE is currently one of the “smartest” search engines in the world. It has been trained like a student who went through elementary school (general reading), high school (specific facts), and then a PhD program (answering hard questions). This makes it incredibly good at understanding exactly what you’re looking for, even if your query is phrased in a confusing way.

How It Works

BGE is a series of open-source embedding models from the Beijing Academy of Artificial Intelligence (BAAI). These models are specifically optimized for retrieval tasks using a multi-stage training curriculum that includes massive-scale pre-training and fine-grained instruction tuning.

Example

var architecture = new NeuralNetworkArchitecture<float>(inputFeatures: 8, outputSize: 4);
var input = Tensor<float>.CreateRandom(new[] { 1, 512 });
var trainX = Tensor<float>.CreateRandom(4, 8);
var trainY = Tensor<float>.CreateRandom(4, 2);
var result = new AiModelBuilder<float, Tensor<float>, Tensor<float>>()
    .ConfigureModel(new BGE<float>(architecture))
    .Build(trainX, trainY);
var embedding = result.Predict(input);

Constructors

Constructor Summary
BGE() Initializes a new instance of the BGE model.
BGE(NeuralNetworkArchitecture<T> architecture, BGEOptions options, ITokenizer tokenizer, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction)

Methods

Method Summary
ModelMetadata<T> GetModelMetadata() Retrieves metadata about the BGE model.
Task<Matrix<T>> EmbedBatchAsync(IEnumerable<string> texts)
Task<Vector<T>> EmbedAsync(string text)
Vector<T> Embed(string text)