Portal Community

What is Semantic Memory?

Semantic memory stores what the agent knows — general facts, domain knowledge, company policies, product documentation. Unlike episodic memory (past conversations) or working memory (current context), semantic memory is persistent and separate from any particular conversation.

Technically, semantic memory is a vector database where each record contains:

How Retrieval Works

1

User Message Arrives

The user's message is the query for semantic retrieval.

2

Embed the Query

IEmbeddingProvider.EmbedAsync(userMessage) → float[] vector representing the query's meaning.

3

Vector Similarity Search

The query vector is compared against all indexed document chunks using cosine similarity. Top-K most similar chunks are returned.

4

Inject into Context

Retrieved chunks are formatted as a [Retrieved Knowledge] block and placed in the LLM context before the user's message.

5

Grounded Response

The LLM answers based on the retrieved knowledge — not hallucinating, but citing actual content from the knowledge base.

ISemanticMemoryStore Interface

public interface ISemanticMemoryStore
{
    Task StoreAsync(
        MemoryRecord record,
        CancellationToken ct = default);

    Task<IReadOnlyList<MemoryRecord>> SearchAsync(
        string collection,         // agent-scoped collection name
        float[] queryEmbedding,
        int topK = 5,
        float minScore = 0.7f,
        MemoryFilter? filter = null,
        CancellationToken ct = default);

    Task DeleteAsync(
        string collection,
        string recordId,
        CancellationToken ct = default);

    Task<bool> CollectionExistsAsync(string collection, CancellationToken ct = default);
    Task CreateCollectionAsync(string collection, int vectorSize, CancellationToken ct = default);
}

public class MemoryRecord
{
    public string Id { get; set; }
    public string Collection { get; set; }    // "agent_{agentId}_{tenantId}"
    public string Content { get; set; }
    public float[] Embedding { get; set; }
    public MemoryMetadata Metadata { get; set; }
}

public class MemoryMetadata
{
    public string Source { get; set; }       // source document name
    public int ChunkIndex { get; set; }      // chunk position in source
    public string Category { get; set; }     // "policy", "manual", "faq"
    public DateTimeOffset IndexedAt { get; set; }
    public string TenantId { get; set; }
    public string AgentId { get; set; }
}

Vector Database Backends

BackendBest ForDeploymentScaling
QdrantHigh performance, large corporaDocker / Qdrant CloudHorizontal sharding
PGVectorSimpler ops, existing PostgreSQL stackPostgreSQL extensionLimited — vertical only
In-MemoryDevelopment / testing onlyIn-processNot for production
Collection per Agent

Each agent has its own vector collection, named agent_{agentId}_{tenantId}. This hard-isolates knowledge — an HR agent cannot accidentally retrieve documents from the Finance agent's knowledge base, even within the same tenant.