KGEmbeddingBase<T>

Base Classes · AiDotNet.RetrievalAugmentedGeneration.Graph.Embeddings

Abstract base class for knowledge graph embedding models providing shared training infrastructure.

Implements: IKnowledgeGraphEmbedding<T>

Known derived types: ComplExEmbedding<T>, DistMultEmbedding<T>, RotatEEmbedding<T>, TemporalTransEEmbedding<T>, TransEEmbedding<T>

For Beginners

This class handles the “plumbing” of training:

  1. Builds entity/relation vocabularies from the graph
  2. Initializes random embedding vectors
  3. For each epoch, shuffles triples into mini-batches
  4. For each positive triple, generates corrupted (negative) triples
  5. Computes loss and gradients, then updates embeddings via SGD
  6. Subclasses define how to score triples and compute gradients

How It Works

This base class implements the common training loop with mini-batch SGD and negative sampling. Subclasses only need to implement scoring, gradient computation, and post-epoch normalization.

Properties

Property Summary
bool IsDistanceBased { get; }
bool IsTrained { get; set; }
int EmbeddingDimension { get; }

Methods

Method Summary
KGEmbeddingTrainingResult Train(KnowledgeGraph<T> graph, KGEmbeddingOptions options)
T ScoreTriple(string headId, string relationType, string tailId)
T[] GetEntityEmbedding(string entityId)
T[] GetRelationEmbedding(string relationType)