Metadata-Version: 2.5
Name: zero-context
Version: 0.2.1
Summary: Lightweight Python SDK for the Zero-Context memory engine API
Project-URL: Homepage, https://github.com/ujjwalkat07/Zero-Context
Project-URL: Repository, https://github.com/ujjwalkat07/Zero-Context
Project-URL: Issues, https://github.com/ujjwalkat07/Zero-Context/issues
Author-email: ujjwalkat07 <ukcode07@gmail.com>
License: MIT
Keywords: ai-agents,context,llm,memory,rag
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: httpx>=0.28.0
Requires-Dist: msgspec>=0.22.0
Description-Content-Type: text/markdown

# Zero-Context

A lightweight Python SDK for persistent, semantic AI agent memory powered by Google Gemini embeddings and PostgreSQL `pgvector`.

## Installation

```bash
uv add zero-context
```

Or with `pip`:

```bash
pip install zero-context
```

## Authentication

`ZeroContext` authenticates using an API key (`zc_live_...`). Pass it directly or set the `ZERO_CONTEXT_API_KEY` environment variable:

```bash
export ZERO_CONTEXT_API_KEY="zc_live_your_api_key"
```

## Quickstart

```python
from zero_context import MemoryConfig, ZeroContext

with ZeroContext(
    api_key="zc_live_your_api_key",
    config=MemoryConfig(default_top_k=5, similarity_threshold=0.0),
) as mem:
    # 1. Add memories
    ids = mem.add(
        [
            "User prefers Python and FastAPI.",
            {"role": "user", "content": "I live in San Francisco."},
        ],
        user_id="user_alice",
        session_id="session_01",
    )

    # 2. Search memories
    results = mem.search(
        query="What stack does the user prefer?",
        user_id="user_alice",
    )
    for match in results:
        print(match.memory.text, match.score)

    # 3. Update a memory
    updated = mem.update(
        memory_id=ids[0],
        text="User prefers Python, FastAPI, and Go.",
    )

    # 4. Delete a memory
    mem.delete(ids[1])
```

## API Reference

### `ZeroContext(api_key=None, config=None, timeout=30.0)`
Creates an SDK client instance.
- `api_key` (`str | None`): Your `zc_live_...` API key. Falls back to `ZERO_CONTEXT_API_KEY`.
- `config` (`MemoryConfig | None`): Optional default search/configuration settings.
- `timeout` (`float`): HTTP request timeout in seconds (default `30.0`).

### `mem.add(content, user_id=None, session_id=None, metadata=None) -> list[str]`
Ingests text, a sequence of strings, or chat message dicts (`{"role": ..., "content": ...}`) and returns a list of created memory IDs.

### `mem.search(query, user_id=None, session_id=None, limit=None, threshold=None, metadata_filter=None) -> list[SearchResult]`
Runs semantic nearest-neighbor search and returns ranked `SearchResult` items (`result.memory`, `result.score`).

### `mem.update(memory_id, text, metadata=None) -> MemoryItem`
Updates an existing memory's text (re-embedding it automatically) and optionally replaces its metadata.

### `mem.delete(memory_id) -> bool`
Deletes a memory by ID. Returns `True` if deleted, or `False` if the record was not found.

## Configuration (`MemoryConfig`)

| Field | Default | Description |
| --- | --- | --- |
| `default_top_k` | `5` | Default maximum results returned by `search()` |
| `similarity_threshold` | `0.0` | Minimum cosine similarity score for `search()` |
| `dimension` | `768` | Embedding vector dimension |
| `max_context_chars` | `1500` | Maximum context character budget |

## Error Handling

All SDK errors inherit from `ZeroContextError`:
- `ZeroContextError`: Missing API key or general client configuration error.
- `MemoryNotFoundError`: Raised on `404` when updating a non-existent memory ID.
- `StorageError`: Raised on backend API errors (`4xx`/`5xx`).

## License

MIT
