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="...",
)

Optional fields:

client = MemoryClient(
    ...,
    pinecone_namespace="tenant-a",   # Multi-tenant within one Pinecone index
    neo4j_database="mydb",           # Neo4j database name (defaults to "neo4j")
    base_url="https://xvert.io",     # API base URL
    timeout=30,                       # Request timeout in seconds
)

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.1.tar.gz (6.3 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.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: comemo-1.0.1.tar.gz
  • Upload date:
  • Size: 6.3 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.1.tar.gz
Algorithm Hash digest
SHA256 0e269e3669183e5ac555031a5d10a364ed6da670f8b7af903ec87a7a456c4fbf
MD5 0ad33b0ac4643d88cb0a42d158b01995
BLAKE2b-256 0f8214949d7977cf15f2a6c5b504edc45f2a44513dff47ea05a151a2fc570464

See more details on using hashes here.

File details

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

File metadata

  • Download URL: comemo-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.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.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 366babf6b971c7353751b242e91a26c0b6d22bf1884e02b804ded1a2ec6998bd
MD5 1848fee92b290d4950eb7f506fa3fd89
BLAKE2b-256 cc349d218614f690ffa0387434dccb04db19aa21d0705a4df6a6aaa019bd2b0c

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