Semantic Memory

Semantic memory uses vector embeddings to store and retrieve knowledge by meaning. It powers RAG (Retrieval-Augmented Generation) use cases.

Overview

SemanticMemory stores text chunks as embeddings in a vector store (backed by pgvector or a compatible database). When the agent needs context, it retrieves the most semantically relevant chunks.

Setup

Semantic memory requires the embeddings module and pgvector:

uv add "djangosdk[pgvector]"
# settings.py
DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        ...
    }
}

AI_SDK = {
    "DEFAULT_PROVIDER": "openai",
    "PROVIDERS": {
        "openai": {"api_key": env("OPENAI_API_KEY")},
    },
}

Usage

Integration with Agents

Embedding Models

Embeddings are generated via the embed() function. The default embedding model is text-embedding-3-small:

See Embeddings for full configuration options.

Last updated

Was this helpful?