TypeScript SDK v3 pipeline (full parity with Python): - Single-pass additive extraction with ADDITIVE_EXTRACTION_PROMPT - Hybrid search (semantic + BM25 + entity boost) with additive scoring - 8-phase batch pipeline (batch embed, persist, entity linking) - New utils: scoring.ts, lemmatization.ts (natural), entity_extraction.ts (compromise) - keywordSearch() on 8 vector stores (3 full: PGVector, Memory, Azure AI Search) - Message persistence in SQLiteManager (rolling window of 10) - Entity store as second vector collection - MAX_BATCH=100 chunking guard on OpenAI/Azure embedBatch - Updated default LLM model to gpt-4.1-nano-2025-04-14 - compromise + natural added as peer dependencies Graph store removal (Python + TypeScript): - Removed Neo4j, Memgraph, Kuzu, Neptune, Apache AGE integrations - Deleted 18 graph-related files across both SDKs - Removed GraphStoreFactory, GraphStoreConfig, graph_store config field - Removed "relations" key from all API responses - Removed graph optional dependency group from pyproject.toml - Removed neo4j-driver from TS peerDependencies - Simplified add/search/delete/reset (no more parallel graph operations) Client SDK v3 API migration: - add() endpoint: /v1/memories/ -> /v3/memories/ (async response) - search() endpoint: /v2/memories/search/ -> /v3/memories/search/ - Removed output_format injection and v1.1 unwrapping logic - Applied to both Python (sync + async) and TypeScript clients Review feedback fixes: - Removed deprecated custom_update_memory_prompt from MemoryConfig - Added MAX_BATCH=100 chunking to Python + TS embed_batch - Moved all inline imports to top level in main.py - Cleaned up GraphStoreError dead code from exceptions.py Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
82 lines
3.2 KiB
Python
82 lines
3.2 KiB
Python
import os
|
|
from typing import Any, Dict, Optional
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
from mem0.configs.rerankers.config import RerankerConfig
|
|
from mem0.embeddings.configs import EmbedderConfig
|
|
from mem0.llms.configs import LlmConfig
|
|
from mem0.vector_stores.configs import VectorStoreConfig
|
|
|
|
# Set up the directory path
|
|
home_dir = os.path.expanduser("~")
|
|
mem0_dir = os.environ.get("MEM0_DIR") or os.path.join(home_dir, ".mem0")
|
|
|
|
|
|
class MemoryItem(BaseModel):
|
|
id: str = Field(..., description="The unique identifier for the text data")
|
|
memory: str = Field(
|
|
..., description="The memory deduced from the text data"
|
|
) # TODO After prompt changes from platform, update this
|
|
hash: Optional[str] = Field(None, description="The hash of the memory")
|
|
# The metadata value can be anything and not just string. Fix it
|
|
metadata: Optional[Dict[str, Any]] = Field(None, description="Additional metadata for the text data")
|
|
score: Optional[float] = Field(None, description="The score associated with the text data")
|
|
created_at: Optional[str] = Field(None, description="The timestamp when the memory was created")
|
|
updated_at: Optional[str] = Field(None, description="The timestamp when the memory was updated")
|
|
|
|
|
|
class MemoryConfig(BaseModel):
|
|
vector_store: VectorStoreConfig = Field(
|
|
description="Configuration for the vector store",
|
|
default_factory=VectorStoreConfig,
|
|
)
|
|
llm: LlmConfig = Field(
|
|
description="Configuration for the language model",
|
|
default_factory=LlmConfig,
|
|
)
|
|
embedder: EmbedderConfig = Field(
|
|
description="Configuration for the embedding model",
|
|
default_factory=EmbedderConfig,
|
|
)
|
|
history_db_path: str = Field(
|
|
description="Path to the history database",
|
|
default=os.path.join(mem0_dir, "history.db"),
|
|
)
|
|
reranker: Optional[RerankerConfig] = Field(
|
|
description="Configuration for the reranker",
|
|
default=None,
|
|
)
|
|
version: str = Field(
|
|
description="The version of the API",
|
|
default="v1.1",
|
|
)
|
|
custom_instructions: Optional[str] = Field(
|
|
description="Custom instructions for fact extraction",
|
|
default=None,
|
|
)
|
|
|
|
|
|
class AzureConfig(BaseModel):
|
|
"""
|
|
Configuration settings for Azure.
|
|
|
|
Args:
|
|
api_key (str): The API key used for authenticating with the Azure service.
|
|
azure_deployment (str): The name of the Azure deployment.
|
|
azure_endpoint (str): The endpoint URL for the Azure service.
|
|
api_version (str): The version of the Azure API being used.
|
|
default_headers (Dict[str, str]): Headers to include in requests to the Azure API.
|
|
"""
|
|
|
|
api_key: str = Field(
|
|
description="The API key used for authenticating with the Azure service.",
|
|
default=None,
|
|
)
|
|
azure_deployment: str = Field(description="The name of the Azure deployment.", default=None)
|
|
azure_endpoint: str = Field(description="The endpoint URL for the Azure service.", default=None)
|
|
api_version: str = Field(description="The version of the Azure API being used.", default=None)
|
|
default_headers: Optional[Dict[str, str]] = Field(
|
|
description="Headers to include in requests to the Azure API.", default=None
|
|
)
|