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

Implementation:24kchengYe MemoMind generate embeddings batch

From Leeroopedia
Knowledge Sources
Domains NLP, Representation_Learning
Last Updated 2026-10-28 00:00 GMT

Overview

Concrete tool for generating vector embeddings from fact texts with temporal and entity augmentation, provided by the MemoMind retain pipeline.

Description

The generate_embeddings_batch function generates embeddings for a list of fact text strings. Before embedding, texts are augmented with human-readable date strings and entity names via augment_texts_with_dates, so that the resulting vectors encode temporal and entity context for better semantic retrieval.

The function delegates to embedding_utils.generate_embeddings_batch, which runs the embeddings backend's `encode()` method in a thread pool executor to avoid blocking the asyncio event loop for CPU-bound operations (local sentence-transformers models).

The embeddings backend is pluggable: LocalSTEmbeddings (BGE-M3 by default), OpenAIEmbeddings, CohereEmbeddings, or LiteLLMEmbeddings.

Usage

Import this function when you need to convert extracted facts into vector embeddings for storage and semantic retrieval. It is called by the retain orchestrator after fact extraction.

Code Reference

Source Location

  • Repository: MemoMind
  • File: engine/hindsight_api/engine/retain/embedding_processing.py
  • Lines: L49-65 (delegates to embedding_utils.py:L29-52; augmentation at L15-46)

Signature

async def generate_embeddings_batch(
    embeddings_model,
    texts: list[str],
) -> list[list[float]]:

Import

from hindsight_api.engine.retain.embedding_processing import generate_embeddings_batch, augment_texts_with_dates

I/O Contract

Inputs

Name Type Required Description
embeddings_model Embeddings Yes Embeddings backend instance (sentence-transformers, OpenAI, etc.)
texts list[str] Yes Augmented fact text strings to embed

Outputs

Name Type Description
embeddings list[list[float]] Embedding vectors (same length as input texts, dimension depends on backend)

Usage Examples

Generating Embeddings with Date Augmentation

import asyncio
from hindsight_api.engine.retain.embedding_processing import (
    generate_embeddings_batch,
    augment_texts_with_dates,
)
from hindsight_api.engine.embeddings import create_embeddings_from_env
from datetime import datetime

async def main():
    embeddings_model = create_embeddings_from_env()  # Defaults to BGE-M3

    facts = [...]  # list of ExtractedFact objects
    format_date_fn = lambda d: d.strftime("%B %d, %Y")

    # Step 1: Augment texts with dates and entity names
    augmented_texts = augment_texts_with_dates(facts, format_date_fn)
    # e.g., "Alice got promoted (happened in June 15, 2024) [Alice, Acme Corp]"

    # Step 2: Generate embeddings
    embeddings = await generate_embeddings_batch(embeddings_model, augmented_texts)
    print(f"Generated {len(embeddings)} embeddings, dim={len(embeddings[0])}")

asyncio.run(main())

Related Pages

Implements Principle

Requires Environment

Uses Heuristics

Page Connections

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