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.2.0.tar.gz (7.4 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.2.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for comemo-1.2.0.tar.gz
Algorithm Hash digest
SHA256 42d9e4277d52cfd1b51f4c46901e356a7ce2711f904ef4d86604642d63de744b
MD5 b23b6f727f45ca1b3ea671747d3ac140
BLAKE2b-256 c4224bee4056cf931f511fa8225129ac9dc9889144a8b008f42f0c0f1c887908

See more details on using hashes here.

File details

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

File metadata

  • Download URL: comemo-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 deb5e4a86bc69eb3e78042948accf5f4578af559104226d154f37924295aa4cf
MD5 91bf6040693e60a4729bf4c8e81c3d7a
BLAKE2b-256 1306810f877df60a96e062d010b24c1b689ebe970ad91ad7d668b4c06c15dc3b

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