ColBERT<T>

Models & Types · AiDotNet.NeuralNetworks

ColBERT (Contextualized Late Interaction over BERT) neural network implementation. Uses token-level representations for high-precision document retrieval.

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

For Beginners

Most AI search models are like people who read a whole book and then try to summarize it in just one word. ColBERT is like a person who keeps detailed notes on every single word. When you ask a question, ColBERT compares every word in your question to every word in the document notes. This is much more accurate because no information is “lost” during summarization.

How It Works

ColBERT is a highly efficient and accurate retrieval model that keeps a separate vector for every token in a sentence. It calculates the similarity between a query and a document using a “Late Interaction” MaxSim operator, allowing it to capture fine-grained semantic matches.

Example

var architecture = new NeuralNetworkArchitecture<float>(inputFeatures: 8, outputSize: 4);
var input = Tensor<float>.CreateRandom(new[] { 1, 32 });
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 ColBERT<float>(architecture))
    .Build(trainX, trainY);
var embedding = result.Predict(input);

Constructors

Constructor Summary
ColBERT() Initializes a new instance with default architecture settings.
ColBERT(NeuralNetworkArchitecture<T> architecture, ColBERTOptions options, ITokenizer tokenizer, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Initializes a new instance of the ColBERT model.

Methods

Method Summary
Matrix<T> EmbedLateInteraction(string text) Encodes text into a multi-vector matrix where each row is a contextualized token embedding.
Matrix<T> EmbedQueryLateInteraction(string query) Encodes a search query the way ColBERT’s query encoder does: exactly MaxQueryLength token embeddings.
ModelMetadata<T> GetModelMetadata() Retrieves metadata about the ColBERT model.
T LateInteractionScore(Matrix<T> queryEmbeddings, Matrix<T> docEmbeddings) Computes the similarity score between a query and document matrix using the MaxSim interaction.
Vector<T> Embed(string text) Fallback method that encodes a sentence into a single summary vector (mean-pooled).