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.1.0.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.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: comemo-1.1.0.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.1.0.tar.gz
Algorithm Hash digest
SHA256 7978a84c33c4c2a90bd86c346eceb0108c86ce91d04d4bc9d07ae7677e2a1c30
MD5 cf1d0a93a7dcdcadfb0cb37806e3b9d2
BLAKE2b-256 4ffcfc19a27e5be5719916997025ece11de724e02af8e5e6b8b23f3c2e133e29

See more details on using hashes here.

File details

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

File metadata

  • Download URL: comemo-1.1.0-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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7d0588f5e526b9b9802fcd537152e294a88f066213d02cfab875b65e750647dc
MD5 c8fd819b33f24fb961bbb378f3a079c4
BLAKE2b-256 737190349cd649978fea829d8200cd49258f40924d85507f48ca448f958eae68

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