Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Environment:24kchengYe MemoMind Embeddings Backend

From Leeroopedia
Knowledge Sources
Domains Infrastructure, Embeddings
Last Updated 2026-10-28 14:45 GMT

Overview

Embedding model backend (default: BAAI/bge-m3 for production, BAAI/bge-small-en-v1.5 for local dev) for generating vector representations used in semantic search and memory consolidation.

Description

This environment provides the embedding model used to vectorize facts and queries for semantic retrieval. MemoMind supports multiple backends: local (SentenceTransformers, default), OpenAI (`text-embedding-3-small`), Cohere (`embed-english-v3.0`), TEI (Text Embeddings Inference server), and LiteLLM. The embedding dimension is auto-detected from the model at initialization and the database schema is automatically adjusted to match. The production Docker image pre-downloads `BAAI/bge-m3` (1024-dim) into the container. Local mode auto-detects GPU (CUDA) or Apple Silicon (MPS), falling back to CPU.

Usage

Use this environment for embedding generation during the retain pipeline (fact text → vectors), recall (query → vector), and consolidation (observation text → vectors). Required by any implementation that creates or searches vector embeddings.

System Requirements

Category Requirement Notes
OS Linux / macOS CPU-only in production Docker; GPU optional for local
Hardware 4GB+ RAM (local) bge-m3 model ~2.4GB; CPU inference ~80ms/100 pairs
Disk 3GB+ for model cache `HF_HOME=/models` in Docker; SentenceTransformers cache dir otherwise
GPU Optional (CUDA or MPS) Auto-detected; CPU fallback supported

Dependencies

Python Packages

  • `sentence-transformers` >= 2.2 — Local embedding model (for `local` provider)
  • `torch` — Backend for SentenceTransformers (CPU-only wheel in production Docker)
  • `httpx` — HTTP client for remote embedding APIs (OpenAI, Cohere, TEI, LiteLLM)
  • `numpy` — Score normalization

Models

  • `BAAI/bge-m3` — Production default (pre-downloaded in Docker, 1024-dim)
  • `BAAI/bge-small-en-v1.5` — Local dev default (384-dim)
  • `text-embedding-3-small` — OpenAI embeddings API (1536-dim)
  • `embed-english-v3.0` — Cohere embeddings API

Credentials

The following environment variables must be set in `.env`:

  • `HINDSIGHT_API_EMBEDDINGS_PROVIDER`: Backend name (default: `local`; options: `local`, `openai`, `cohere`, `tei`, `litellm`, `litellm-sdk`)

For `local` provider:

  • `HINDSIGHT_API_EMBEDDINGS_LOCAL_MODEL`: Model name (default: `BAAI/bge-small-en-v1.5`)
  • `HINDSIGHT_API_EMBEDDINGS_LOCAL_FORCE_CPU`: Force CPU mode (default: `false`; avoids MPS/XPC issues on macOS daemon mode)
  • `HINDSIGHT_API_EMBEDDINGS_LOCAL_TRUST_REMOTE_CODE`: Allow custom model code (default: `false` — security)

For `openai` provider:

  • `HINDSIGHT_API_EMBEDDINGS_OPENAI_API_KEY`: OpenAI API key
  • `HINDSIGHT_API_EMBEDDINGS_OPENAI_MODEL`: Model (default: `text-embedding-3-small`)
  • `HINDSIGHT_API_EMBEDDINGS_OPENAI_BASE_URL`: Custom base URL (optional)

For `cohere` provider:

  • `HINDSIGHT_API_EMBEDDINGS_COHERE_API_KEY`: Cohere API key
  • `HINDSIGHT_API_EMBEDDINGS_COHERE_MODEL`: Model (default: `embed-english-v3.0`)

For `tei` provider:

  • `HINDSIGHT_API_EMBEDDINGS_TEI_URL`: TEI server URL

Quick Install

# Local embeddings (SentenceTransformers + CPU torch)
pip install sentence-transformers
pip install torch --index-url https://download.pytorch.org/whl/cpu

# Pre-download production model
python -c "from huggingface_hub import snapshot_download; snapshot_download('BAAI/bge-m3')"

Code Evidence

Embedding model defaults from `config.py:378-383`:

DEFAULT_EMBEDDINGS_PROVIDER = "local"
DEFAULT_EMBEDDINGS_LOCAL_MODEL = "BAAI/bge-small-en-v1.5"
DEFAULT_EMBEDDINGS_LOCAL_FORCE_CPU = False
DEFAULT_EMBEDDINGS_OPENAI_MODEL = "text-embedding-3-small"
DEFAULT_EMBEDDING_DIMENSION = 384

GPU auto-detection from `embeddings.py:151-162`:

device = "cpu"  # Default to CPU
try:
    has_gpu = torch.cuda.is_available() or (
        hasattr(torch.backends, "mps") and torch.backends.mps.is_available()
    )
    if has_gpu:
        device = None  # Let sentence-transformers auto-detect GPU/MPS
except Exception as e:
    logger.warning(f"Failed to detect GPU/MPS, falling back to CPU: {e}")

Docker model pre-download from `deploy/server/Dockerfile:13-15`:

RUN python -c "from huggingface_hub import snapshot_download; \
    snapshot_download('BAAI/bge-m3'); \
    snapshot_download('cross-encoder/ms-marco-MiniLM-L-6-v2')"

Import guard from `embeddings.py:132-137`:

from sentence_transformers import SentenceTransformer
except ImportError:
    raise ImportError(
        "sentence-transformers is required for LocalSTEmbeddings. "
        "Install it with: pip install sentence-transformers"
    )

Common Errors

Error Message Cause Solution
`sentence-transformers is required for LocalSTEmbeddings` Package not installed `pip install sentence-transformers`
`initialize()` not called before `encode()` | Call `await embeddings.initialize()` during startup
Model download fails (HuggingFace) No internet or HF blocked Pre-download model; set `HF_HOME` to local cache
MPS/XPC issues on macOS daemon mode Set `HINDSIGHT_API_EMBEDDINGS_LOCAL_FORCE_CPU=true`

Compatibility Notes

  • Dimension auto-detection: The schema's vector column is adjusted at runtime to match the model's actual dimension (e.g., 384 for bge-small, 1024 for bge-m3, 1536 for OpenAI).
  • macOS daemon mode: Set `FORCE_CPU=true` to avoid MPS/XPC instability when running as a background daemon.
  • trust_remote_code: Disabled by default for security. Required for some models with custom architectures (e.g., jina). Enable only with trusted model sources.
  • Production Docker: Uses CPU-only torch (`--index-url https://download.pytorch.org/whl/cpu`) to avoid pulling multi-GB CUDA wheels. Models are baked into the image via `HF_HOME=/models`.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment