MCPcopy
hub / github.com/CaviraOSS/OpenMemory / OpenMemory

Class OpenMemory

sdk-py/src/openmemory/__init__.py:18–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16from openmemory.utils.chunking import chunk_text
17
18class OpenMemory:
19 def __init__(self, mode="local", path=None, url=None, apiKey=None, tier=None, embeddings=None, compression=None, decay=None, reflection=None, vectorStore=None, langGraph=None):
20 self.mode = mode
21 self.url = url
22 self.api_key = apiKey
23
24 if self.mode == "remote":
25 if not self.url:
26 raise ValueError("Remote mode requires url parameter")
27 else:
28 # Local mode configuration
29 if not path:
30 raise ValueError('Local mode requires "path" configuration (e.g., "./data/memory.sqlite").')
31 if not tier:
32 raise ValueError('Local mode requires "tier" configuration (e.g., "fast", "smart", "deep", "hybrid").')
33 if not embeddings:
34 raise ValueError('Local mode requires "embeddings" configuration. Please specify a provider (e.g., openai, ollama, synthetic).')
35
36 provider = embeddings.get("provider")
37 emb_api_key = embeddings.get("apiKey")
38 aws_config = embeddings.get("aws")
39
40 if provider in ["openai", "gemini"] and not emb_api_key:
41 raise ValueError(f"API key is required for {provider} embeddings.")
42
43 if provider == "aws" and (not aws_config or not aws_config.get("accessKeyId") or not aws_config.get("secretAccessKey")):
44 raise ValueError("AWS credentials (accessKeyId, secretAccessKey) are required for AWS embeddings.")
45
46 config_update = {}
47 config_update["db_path"] = path
48 config_update["tier"] = tier
49
50 config_update["emb_kind"] = provider
51 if embeddings.get("mode"): config_update["embed_mode"] = embeddings["mode"]
52 if embeddings.get("dimensions"): config_update["vec_dim"] = embeddings["dimensions"]
53
54 if emb_api_key:
55 if provider == "openai": config_update["openai_key"] = emb_api_key
56 if provider == "gemini": config_update["gemini_key"] = emb_api_key
57
58 if embeddings.get("model"):
59 if provider == "openai": config_update["openai_model"] = embeddings["model"]
60 if provider == "ollama": config_update["ollama_model"] = embeddings["model"]
61
62 if aws_config:
63 config_update["AWS_ACCESS_KEY_ID"] = aws_config.get("accessKeyId")
64 config_update["AWS_SECRET_ACCESS_KEY"] = aws_config.get("secretAccessKey")
65 config_update["AWS_REGION"] = aws_config.get("region")
66
67 if embeddings.get("ollama") and embeddings["ollama"].get("url"):
68 config_update["ollama_url"] = embeddings["ollama"]["url"]
69
70 if embeddings.get("localPath"):
71 config_update["local_model_path"] = embeddings["localPath"]
72
73 # ... map other options ...
74
75 configure(config_update)

Callers 8

test_sdk_initializationFunction · 0.90
test_memory_operationsFunction · 0.90
test_sector_operationsFunction · 0.90
test_advanced_featuresFunction · 0.90
sector_exampleFunction · 0.90
basic_exampleFunction · 0.90
advanced_exampleFunction · 0.90
benchmarkFunction · 0.90

Calls

no outgoing calls

Tested by 4

test_sdk_initializationFunction · 0.72
test_memory_operationsFunction · 0.72
test_sector_operationsFunction · 0.72
test_advanced_featuresFunction · 0.72