Unreal: Embeddings & Search
Embeddings, vector search, and hybrid search in Unreal Engine. For the concepts behind each step see the guide pages on Embedding Models, Vector Search, and Hybrid & Lexical Search.
KV-store entries and queries are JSON strings; the store takes vectors you
produce with Embed, not raw text. embed_dim must match the model — 384 for
MiniLM/bge-small, 768 for bge-base.
Embed text
const FString Model = TEXT("in-memory::sentence-transformers/all-MiniLM-L6-v2");
const FString Resp = Atelico->Embed(FString::Printf(TEXT(R"({
"model": "%s",
"input": ["The guard saw a thief enter the keep at midnight."]
})"), *Model));
// Parse Resp -> data[0].embedding into a TArray<float>.
// Or a direct cosine similarity between two strings:
float Sim = Atelico->Similarity(Model, TEXT("a knight's blade"), TEXT("a warrior's sword"));
Create a store, insert, query
// 1. Create
Atelico->CreateKvStore(TEXT(R"({
"store_id": "npc-memory",
"db_path": "./data/npc-memory",
"embed_dim": 384
})"));
// 2. Insert — key_embedding is the vector from Embed (EmbeddingCsv = comma-joined floats)
const FString Entries = FString::Printf(TEXT(R"([{
"id": "mem-001",
"key_text": "The guard saw a thief enter the keep at midnight.",
"key_embedding": [%s],
"facets": {"npc_id": "guard-01", "location": "keep"},
"priority": 0.8
}])"), *EmbeddingCsv);
Atelico->KvStoreInsert(TEXT("npc-memory"), Entries);
// 3. Query — embed the question first, pass the vector
const FString Query = FString::Printf(TEXT(R"({
"query_embedding": [%s],
"facet_filters": {"npc_id": "guard-01"},
"limit": 5
})"), *QueryEmbeddingCsv);
FString Results = Atelico->KvStoreQuery(TEXT("npc-memory"), Query);
// Results: JSON array of {id, key_text, similarity, priority, combined_score}
uint64 Count = Atelico->KvStoreCount(TEXT("npc-memory"), TEXT(""));
Hybrid (vector + keyword) search
Atelico->KvStoreCreateFtsIndex(TEXT("npc-memory"), TEXT("key_text"));
const FString Hybrid = FString::Printf(TEXT(R"({
"embeddings": [%s],
"text": "thief keep",
"fts_column": "key_text",
"limit": 5,
"vector_weight": 0.6,
"lexical_weight": 0.4
})"), *QueryEmbeddingCsv);
FString Response = Atelico->KvStoreHybridQuery(TEXT("npc-memory"), Hybrid);
See Hybrid & Lexical Search for the scoring details
and the lexical-only (KvStoreLexicalQuery) variant.