memofai


Namememofai JSON
Version 0.1.1 PyPI version JSON
download
home_pageNone
SummaryPython SDK for MOA (Memory Of Agents) - Revolutionary dual-track AI memory infrastructure
upload_time2025-08-03 19:04:25
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords agents ai memofai memory moa sdk
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # memofai - MOA Python SDK

A comprehensive Python SDK for the MOA (Memory Of Agents) API - Revolutionary dual-track AI memory infrastructure with zero information loss.

[![PyPI version](https://badge.fury.io/py/memofai.svg)](https://badge.fury.io/py/memofai)
[![Python Support](https://img.shields.io/pypi/pyversions/memofai.svg)](https://pypi.org/project/memofai/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## Features

- 🧠 **Memory Operations**: Create, read, update, delete memories with rich metadata
- πŸ” **Hybrid Search**: Vector similarity, keyword matching, fuzzy search, temporal relevance
- πŸ•ΈοΈ **Graph Search**: Advanced graph-based search with multiple algorithms
- πŸ”— **Relationship Management**: AI-powered relationship generation and cleanup
- 🌍 **Multi-Environment**: Support for alpha, beta, and production environments
- πŸ“Š **Analytics**: Memory and relationship statistics
- ⚑ **Async Support**: Full async/await support for high-performance applications
- πŸ”„ **Retry Logic**: Built-in retry mechanisms with exponential backoff
- πŸ›‘οΈ **Type Safety**: Complete type hints and Pydantic models
- πŸ“ **Rich Documentation**: Comprehensive examples and API reference

## Installation

```bash
pip install memofai
```

For development with all optional dependencies:

```bash
pip install memofai[dev,docs]
```

## Quick Start

### Basic Usage

```python
from memofai import MOAClient, Environment

# Initialize client
client = MOAClient(
    api_key="your-api-key",
    environment=Environment.BETA
)

# Create a memory
response = client.memory.create_memory({
    "content": "Important meeting notes from today",
    "tags": ["meeting", "important"],
    "metadata": {"source": "daily-standup", "attendees": 5}
})

print(f"Created memory: {response.memory_id}")

# Search memories
results = client.memory.search_memories(
    query="meeting notes",
    max_results=10,
    vector_weight=0.7,  # Emphasize semantic similarity
    keyword_weight=0.3
)

for result in results.results:
    print(f"Score: {result.score:.2f} - {result.memory.content[:100]}")

# Close the client
client.close()
```

### Environment-Specific Clients

```python
from memofai import MOAClient

# Direct environment methods
alpha_client = MOAClient.for_alpha("your-alpha-key")
beta_client = MOAClient.for_beta("your-beta-key") 
prod_client = MOAClient.for_production("your-prod-key")

# Or using environment variables
# Set MOA_API_KEY, MOA_ENVIRONMENT, etc.
client = MOAClient.from_env()
```

### Async Usage

```python
import asyncio
from memofai import MOAClient

async def main():
    async with MOAClient(api_key="your-api-key") as client:
        # Async memory operations
        response = await client.memory.acreate_memory({
            "content": "Async memory creation",
            "tags": ["async", "example"]
        })
        
        # Async search
        results = await client.memory.asearch_memories(
            query="async example",
            max_results=5
        )
        
        print(f"Found {len(results.results)} memories")

asyncio.run(main())
```

### Graph Search

```python
# Find shortest paths between memories
graph_results = client.graph.search_shortest_path(
    query="project updates",
    max_depth=3,
    min_relationship_strength=0.5
)

# Find semantic clusters
clusters = client.graph.search_similarity_cluster(
    query="machine learning concepts",
    max_depth=2,
    min_concept_relevance=0.6
)

# Temporal flow analysis
temporal_results = client.graph.search_temporal_flow(
    query="product development timeline",
    weight_by_recency=True
)
```

### Relationship Management

```python
# Generate relationships for all memories
response = client.relationships.generate_all_relationships(
    force_regenerate=False,
    batch_size=10
)

print(f"Generated {response.stats['created']} new relationships")

# Get relationship statistics
stats = client.relationships.get_relationship_stats()
print(f"Total relationships: {stats.total_relationships}")
print(f"Average strength: {stats.average_strength:.2f}")

# Clean up weak relationships
cleanup = client.relationships.cleanup_weak_relationships(
    min_strength=0.3
)
print(f"Removed {cleanup.removed_count} weak relationships")
```

## Configuration

### Environment Variables

Set these environment variables to configure the SDK:

```bash
export MOA_API_KEY="your-api-key"
export MOA_ENVIRONMENT="beta"  # alpha, beta, production
export MOA_API_VERSION="v1"
export MOA_TIMEOUT="30.0"
export MOA_MAX_RETRIES="3"
export MOA_RETRY_DELAY="1.0"
export MOA_DEBUG="false"
```

### Programmatic Configuration

```python
from memofai import MOAClient, Environment

client = MOAClient(
    api_key="your-api-key",
    environment=Environment.PRODUCTION,
    api_version="v1",
    timeout=60.0,
    max_retries=5,
    retry_delay=2.0,
    debug=True
)
```

## API Reference

### Memory Operations

- `create_memory(request)` - Create a new memory
- `get_memory(memory_id)` - Retrieve a specific memory
- `update_memory(memory_id, request)` - Update an existing memory
- `delete_memory(memory_id)` - Delete a memory
- `search_memories(query, **params)` - Search memories with hybrid approach
- `get_analytics()` - Get memory analytics

### Graph Search Operations

- `graph_search(request)` - Perform advanced graph search
- `search_shortest_path(query, **params)` - Find shortest paths
- `search_similarity_cluster(query, **params)` - Find semantic clusters
- `search_concept_traversal(query, **params)` - Concept-based search
- `search_temporal_flow(query, **params)` - Temporal sequence search
- `search_causal_chain(query, **params)` - Causal relationship discovery
- `get_search_types()` - Get available search types

### Relationship Operations

- `generate_relationships(request)` - Generate relationships with AI
- `generate_all_relationships(**params)` - Generate for all memories
- `generate_relationships_for_memories(memory_ids, **params)` - Generate for specific memories
- `get_relationship_stats()` - Get relationship statistics
- `cleanup_relationships(min_strength)` - Clean up weak relationships
- `optimize_graph(**params)` - Full graph optimization

## Examples

Check out the [examples](examples/) directory for more comprehensive examples:

- [basic_usage.py](examples/basic_usage.py) - Basic memory operations
- [graph_search_example.py](examples/graph_search_example.py) - Graph search patterns
- [memory_management.py](examples/memory_management.py) - Advanced memory management

## Error Handling

The SDK provides specific exception types for different error scenarios:

```python
from memofai import MOAClient
from memofai.exceptions import (
    MOAAuthError,
    MOANotFoundError,
    MOARateLimitError,
    MOAValidationError,
    MOAConnectionError,
    MOATimeoutError
)

try:
    client = MOAClient(api_key="invalid-key")
    response = client.memory.create_memory({"content": "test"})
except MOAAuthError:
    print("Authentication failed - check your API key")
except MOAValidationError as e:
    print(f"Validation error: {e.message}")
    print(f"Details: {e.details}")
except MOARateLimitError as e:
    print(f"Rate limited - retry after {e.retry_after} seconds")
except Exception as e:
    print(f"Unexpected error: {e}")
```

## Development

### Setup Development Environment

```bash
git clone https://github.com/memof-ai/moa-sdk-python.git
cd moa-sdk-python

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install development dependencies
pip install -e ".[dev,docs]"

# Install pre-commit hooks
pre-commit install
```

### Running Tests

```bash
# Run all tests
pytest

# Run with coverage
pytest --cov=moa --cov-report=html

# Run specific test file
pytest tests/test_memory.py -v
```

### Code Quality

```bash
# Format code
black moa/ tests/ examples/

# Lint code
ruff check moa/ tests/ examples/

# Type checking
mypy moa/
```

## Contributing

We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.

1. Fork the repository
2. Create a feature branch: `git checkout -b feature-name`
3. Make your changes and add tests
4. Ensure tests pass: `pytest`
5. Submit a pull request

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Support

- πŸ“§ Email: [hello@memof.ai](mailto:hello@memof.ai)
- 🌐 Website: [https://memof.ai](https://memof.ai)
- πŸ“– Documentation: [https://docs.memof.ai](https://docs.memof.ai)
- πŸ› Issues: [GitHub Issues](https://github.com/memof-ai/moa-sdk-python/issues)

## Changelog

See [CHANGELOG.md](CHANGELOG.md) for a list of changes and version history.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "memofai",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "agents, ai, memofai, memory, moa, sdk",
    "author": null,
    "author_email": "MOA Team <hello@memof.ai>",
    "download_url": "https://files.pythonhosted.org/packages/6c/f0/0dbc73e35b6a17e01388e61b3227046c6aa9c568fb1c5b6c057a110c9daf/memofai-0.1.1.tar.gz",
    "platform": null,
    "description": "# memofai - MOA Python SDK\n\nA comprehensive Python SDK for the MOA (Memory Of Agents) API - Revolutionary dual-track AI memory infrastructure with zero information loss.\n\n[![PyPI version](https://badge.fury.io/py/memofai.svg)](https://badge.fury.io/py/memofai)\n[![Python Support](https://img.shields.io/pypi/pyversions/memofai.svg)](https://pypi.org/project/memofai/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## Features\n\n- \ud83e\udde0 **Memory Operations**: Create, read, update, delete memories with rich metadata\n- \ud83d\udd0d **Hybrid Search**: Vector similarity, keyword matching, fuzzy search, temporal relevance\n- \ud83d\udd78\ufe0f **Graph Search**: Advanced graph-based search with multiple algorithms\n- \ud83d\udd17 **Relationship Management**: AI-powered relationship generation and cleanup\n- \ud83c\udf0d **Multi-Environment**: Support for alpha, beta, and production environments\n- \ud83d\udcca **Analytics**: Memory and relationship statistics\n- \u26a1 **Async Support**: Full async/await support for high-performance applications\n- \ud83d\udd04 **Retry Logic**: Built-in retry mechanisms with exponential backoff\n- \ud83d\udee1\ufe0f **Type Safety**: Complete type hints and Pydantic models\n- \ud83d\udcdd **Rich Documentation**: Comprehensive examples and API reference\n\n## Installation\n\n```bash\npip install memofai\n```\n\nFor development with all optional dependencies:\n\n```bash\npip install memofai[dev,docs]\n```\n\n## Quick Start\n\n### Basic Usage\n\n```python\nfrom memofai import MOAClient, Environment\n\n# Initialize client\nclient = MOAClient(\n    api_key=\"your-api-key\",\n    environment=Environment.BETA\n)\n\n# Create a memory\nresponse = client.memory.create_memory({\n    \"content\": \"Important meeting notes from today\",\n    \"tags\": [\"meeting\", \"important\"],\n    \"metadata\": {\"source\": \"daily-standup\", \"attendees\": 5}\n})\n\nprint(f\"Created memory: {response.memory_id}\")\n\n# Search memories\nresults = client.memory.search_memories(\n    query=\"meeting notes\",\n    max_results=10,\n    vector_weight=0.7,  # Emphasize semantic similarity\n    keyword_weight=0.3\n)\n\nfor result in results.results:\n    print(f\"Score: {result.score:.2f} - {result.memory.content[:100]}\")\n\n# Close the client\nclient.close()\n```\n\n### Environment-Specific Clients\n\n```python\nfrom memofai import MOAClient\n\n# Direct environment methods\nalpha_client = MOAClient.for_alpha(\"your-alpha-key\")\nbeta_client = MOAClient.for_beta(\"your-beta-key\") \nprod_client = MOAClient.for_production(\"your-prod-key\")\n\n# Or using environment variables\n# Set MOA_API_KEY, MOA_ENVIRONMENT, etc.\nclient = MOAClient.from_env()\n```\n\n### Async Usage\n\n```python\nimport asyncio\nfrom memofai import MOAClient\n\nasync def main():\n    async with MOAClient(api_key=\"your-api-key\") as client:\n        # Async memory operations\n        response = await client.memory.acreate_memory({\n            \"content\": \"Async memory creation\",\n            \"tags\": [\"async\", \"example\"]\n        })\n        \n        # Async search\n        results = await client.memory.asearch_memories(\n            query=\"async example\",\n            max_results=5\n        )\n        \n        print(f\"Found {len(results.results)} memories\")\n\nasyncio.run(main())\n```\n\n### Graph Search\n\n```python\n# Find shortest paths between memories\ngraph_results = client.graph.search_shortest_path(\n    query=\"project updates\",\n    max_depth=3,\n    min_relationship_strength=0.5\n)\n\n# Find semantic clusters\nclusters = client.graph.search_similarity_cluster(\n    query=\"machine learning concepts\",\n    max_depth=2,\n    min_concept_relevance=0.6\n)\n\n# Temporal flow analysis\ntemporal_results = client.graph.search_temporal_flow(\n    query=\"product development timeline\",\n    weight_by_recency=True\n)\n```\n\n### Relationship Management\n\n```python\n# Generate relationships for all memories\nresponse = client.relationships.generate_all_relationships(\n    force_regenerate=False,\n    batch_size=10\n)\n\nprint(f\"Generated {response.stats['created']} new relationships\")\n\n# Get relationship statistics\nstats = client.relationships.get_relationship_stats()\nprint(f\"Total relationships: {stats.total_relationships}\")\nprint(f\"Average strength: {stats.average_strength:.2f}\")\n\n# Clean up weak relationships\ncleanup = client.relationships.cleanup_weak_relationships(\n    min_strength=0.3\n)\nprint(f\"Removed {cleanup.removed_count} weak relationships\")\n```\n\n## Configuration\n\n### Environment Variables\n\nSet these environment variables to configure the SDK:\n\n```bash\nexport MOA_API_KEY=\"your-api-key\"\nexport MOA_ENVIRONMENT=\"beta\"  # alpha, beta, production\nexport MOA_API_VERSION=\"v1\"\nexport MOA_TIMEOUT=\"30.0\"\nexport MOA_MAX_RETRIES=\"3\"\nexport MOA_RETRY_DELAY=\"1.0\"\nexport MOA_DEBUG=\"false\"\n```\n\n### Programmatic Configuration\n\n```python\nfrom memofai import MOAClient, Environment\n\nclient = MOAClient(\n    api_key=\"your-api-key\",\n    environment=Environment.PRODUCTION,\n    api_version=\"v1\",\n    timeout=60.0,\n    max_retries=5,\n    retry_delay=2.0,\n    debug=True\n)\n```\n\n## API Reference\n\n### Memory Operations\n\n- `create_memory(request)` - Create a new memory\n- `get_memory(memory_id)` - Retrieve a specific memory\n- `update_memory(memory_id, request)` - Update an existing memory\n- `delete_memory(memory_id)` - Delete a memory\n- `search_memories(query, **params)` - Search memories with hybrid approach\n- `get_analytics()` - Get memory analytics\n\n### Graph Search Operations\n\n- `graph_search(request)` - Perform advanced graph search\n- `search_shortest_path(query, **params)` - Find shortest paths\n- `search_similarity_cluster(query, **params)` - Find semantic clusters\n- `search_concept_traversal(query, **params)` - Concept-based search\n- `search_temporal_flow(query, **params)` - Temporal sequence search\n- `search_causal_chain(query, **params)` - Causal relationship discovery\n- `get_search_types()` - Get available search types\n\n### Relationship Operations\n\n- `generate_relationships(request)` - Generate relationships with AI\n- `generate_all_relationships(**params)` - Generate for all memories\n- `generate_relationships_for_memories(memory_ids, **params)` - Generate for specific memories\n- `get_relationship_stats()` - Get relationship statistics\n- `cleanup_relationships(min_strength)` - Clean up weak relationships\n- `optimize_graph(**params)` - Full graph optimization\n\n## Examples\n\nCheck out the [examples](examples/) directory for more comprehensive examples:\n\n- [basic_usage.py](examples/basic_usage.py) - Basic memory operations\n- [graph_search_example.py](examples/graph_search_example.py) - Graph search patterns\n- [memory_management.py](examples/memory_management.py) - Advanced memory management\n\n## Error Handling\n\nThe SDK provides specific exception types for different error scenarios:\n\n```python\nfrom memofai import MOAClient\nfrom memofai.exceptions import (\n    MOAAuthError,\n    MOANotFoundError,\n    MOARateLimitError,\n    MOAValidationError,\n    MOAConnectionError,\n    MOATimeoutError\n)\n\ntry:\n    client = MOAClient(api_key=\"invalid-key\")\n    response = client.memory.create_memory({\"content\": \"test\"})\nexcept MOAAuthError:\n    print(\"Authentication failed - check your API key\")\nexcept MOAValidationError as e:\n    print(f\"Validation error: {e.message}\")\n    print(f\"Details: {e.details}\")\nexcept MOARateLimitError as e:\n    print(f\"Rate limited - retry after {e.retry_after} seconds\")\nexcept Exception as e:\n    print(f\"Unexpected error: {e}\")\n```\n\n## Development\n\n### Setup Development Environment\n\n```bash\ngit clone https://github.com/memof-ai/moa-sdk-python.git\ncd moa-sdk-python\n\n# Create virtual environment\npython -m venv venv\nsource venv/bin/activate  # On Windows: venv\\Scripts\\activate\n\n# Install development dependencies\npip install -e \".[dev,docs]\"\n\n# Install pre-commit hooks\npre-commit install\n```\n\n### Running Tests\n\n```bash\n# Run all tests\npytest\n\n# Run with coverage\npytest --cov=moa --cov-report=html\n\n# Run specific test file\npytest tests/test_memory.py -v\n```\n\n### Code Quality\n\n```bash\n# Format code\nblack moa/ tests/ examples/\n\n# Lint code\nruff check moa/ tests/ examples/\n\n# Type checking\nmypy moa/\n```\n\n## Contributing\n\nWe welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.\n\n1. Fork the repository\n2. Create a feature branch: `git checkout -b feature-name`\n3. Make your changes and add tests\n4. Ensure tests pass: `pytest`\n5. Submit a pull request\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Support\n\n- \ud83d\udce7 Email: [hello@memof.ai](mailto:hello@memof.ai)\n- \ud83c\udf10 Website: [https://memof.ai](https://memof.ai)\n- \ud83d\udcd6 Documentation: [https://docs.memof.ai](https://docs.memof.ai)\n- \ud83d\udc1b Issues: [GitHub Issues](https://github.com/memof-ai/moa-sdk-python/issues)\n\n## Changelog\n\nSee [CHANGELOG.md](CHANGELOG.md) for a list of changes and version history.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python SDK for MOA (Memory Of Agents) - Revolutionary dual-track AI memory infrastructure",
    "version": "0.1.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/memof-ai/moa-sdk-python/issues",
        "Documentation": "https://docs.memof.ai",
        "Homepage": "https://memof.ai",
        "Repository": "https://github.com/memof-ai/moa-sdk-python"
    },
    "split_keywords": [
        "agents",
        " ai",
        " memofai",
        " memory",
        " moa",
        " sdk"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ed74abe67f489167ab62966d1c99689a5e074fcbf969495085dd1f4e9550865f",
                "md5": "6edd504760bf7b4ac9dcecc77e9d3489",
                "sha256": "a7c5394e702ec13f9379ede4a6a01d1c3c996348be5823b0281a7cc1681c64d7"
            },
            "downloads": -1,
            "filename": "memofai-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6edd504760bf7b4ac9dcecc77e9d3489",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 21246,
            "upload_time": "2025-08-03T19:04:23",
            "upload_time_iso_8601": "2025-08-03T19:04:23.536755Z",
            "url": "https://files.pythonhosted.org/packages/ed/74/abe67f489167ab62966d1c99689a5e074fcbf969495085dd1f4e9550865f/memofai-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "6cf00dbc73e35b6a17e01388e61b3227046c6aa9c568fb1c5b6c057a110c9daf",
                "md5": "814e1ea442a69ba6ea7bb722ad97d627",
                "sha256": "99f10604f4383534212d1aa1457c6cfe226e1d11dc6445570745933a33db782a"
            },
            "downloads": -1,
            "filename": "memofai-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "814e1ea442a69ba6ea7bb722ad97d627",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 28716,
            "upload_time": "2025-08-03T19:04:25",
            "upload_time_iso_8601": "2025-08-03T19:04:25.800273Z",
            "url": "https://files.pythonhosted.org/packages/6c/f0/0dbc73e35b6a17e01388e61b3227046c6aa9c568fb1c5b6c057a110c9daf/memofai-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-03 19:04:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "memof-ai",
    "github_project": "moa-sdk-python",
    "github_not_found": true,
    "lcname": "memofai"
}
        
Elapsed time: 1.52120s