Skip to main content

Python SDK for CoMemo

Project description

CoMemo SDK

Python SDK for CoMemo — a multi-module hybrid memory system powered by Pinecone and Neo4j.

Installation

pip install comemo

Quick Start

Each client requires your own infrastructure credentials. All operations use your own Pinecone index, Neo4j database, and LLM API key.

from comemo import MemoryClient

client = MemoryClient(
    llm_api_key="sk-your-openai-key",
    model="gpt-4o-mini",
    pinecone_api_key="pc-...",
    pinecone_index="my-memory-index",
    neo4j_uri="neo4j+s://xxx.databases.neo4j.io",
    neo4j_username="neo4j",
    neo4j_password="...",
)

Core Memory

# Add a memory
result = client.add_memory("john", "chat_01", "I work at Google as a software engineer")
print(result.status)     # "success"
print(result.action)     # "NEW"
print(result.memory_id)  # "mem_abc123"

# Delete all user memories
client.delete_user_memories("john")

# Delete session memories
client.delete_session_memories("john", "chat_01")

# Delete a single memory
client.delete_memory("mem_abc123")

Retrieval

# Simple retrieve
result = client.retrieve("john", "chat_01", "Where does John work?", top_k=5)
for m in result.memories:
    print(f"{m.fact} (score: {m.score:.2f})")

# Advanced retrieve with full scoring breakdown
result = client.retrieve_advanced(
    user_id="john",
    session_id="chat_01",
    query="career and hobbies",
    top_k=10,
    expand_context=True,
    expand_graph=True,
    min_score=0.3,
    reinforce=True,
)
for m in result.memories:
    print(f"{m.fact} | semantic={m.semantic_similarity:.2f} graph={m.graph_relevance:.2f}")

# List memories across all sessions
result = client.list_memories("john", query="work", top_k=10)

# Retrieve with LLM summary
summary = client.retrieve_summary("john", "chat_01", "Tell me about John's career")
print(summary.summary)

Maintenance

# Run maintenance tasks (decay, forgetting, summarization)
result = client.run_maintenance("john")

# Selective tasks
result = client.run_maintenance(
    "john",
    tasks={"decay": True, "forgetting": True, "summarization": False},
)

# Dry run
result = client.run_maintenance("john", dry_run=True)

System

health = client.health()
print(health.status)        # "healthy"
print(health.version)       # "6.0.0"
print(health.architecture)  # "Multi-Module Hybrid Memory (Multi-Tenant)"

Context Manager

with MemoryClient(
    llm_api_key="sk-...",
    pinecone_api_key="pc-...",
    pinecone_index="my-index",
    neo4j_uri="bolt://localhost:7687",
    neo4j_username="neo4j",
    neo4j_password="...",
) as client:
    client.add_memory("john", "chat_01", "My favorite color is blue")

Error Handling

from comemo import MemoryClient, ValidationError, NotFoundError

try:
    client.retrieve("john", "chat_01", "")
except ValidationError as e:
    print(f"Bad request: {e.message}")
except NotFoundError as e:
    print(f"Not found: {e.message}")

All Methods

Method Description
add_memory(user_id, session_id, text) Extract facts and store as memories
delete_memory(memory_id) Delete a single memory
delete_user_memories(user_id) Delete all memories for a user
delete_session_memories(user_id, session_id) Delete all memories for a session
retrieve(user_id, session_id, query, top_k=5) Simple retrieval
retrieve_advanced(user_id, session_id, query, ...) Advanced retrieval with scoring
list_memories(user_id, query, top_k=10) List memories across sessions
retrieve_summary(user_id, session_id, query, top_k=5) Retrieve with LLM summary
run_maintenance(user_id, tasks=None, dry_run=False) Run tenant-scoped maintenance
health() Health check

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

comemo-1.0.2.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

comemo-1.0.2-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file comemo-1.0.2.tar.gz.

File metadata

  • Download URL: comemo-1.0.2.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for comemo-1.0.2.tar.gz
Algorithm Hash digest
SHA256 b94849abf714953f923e5de9df60eb25275e8992f0e95da3ab44160f513cfaf5
MD5 02fb9534a675d1b295315e7581b61227
BLAKE2b-256 9d7f277b1efbce4c7b0a2e1fd89dac4aa18f5b724ee40079dad064e0e98d6d27

See more details on using hashes here.

File details

Details for the file comemo-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: comemo-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for comemo-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 261bf9b4e42f37daed012198d28d4a59295c3769d7516a442b290e20e30ff8a3
MD5 bb2a95f9b1dd54cbeddd200881357450
BLAKE2b-256 b77c7d8f3e4ad582380729c3ea1f92b76da9347135e4c3bed7b52a13d91161c4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page