Skip to main content

Python client library for the Cortefy API

Project description

Cortefy Python Client

Python client library for the Cortefy API - a semantic memory and search system.

Installation

pip install cortefy

Quick Start

from cortefy import Cortefy
import os

# Initialize the client
client = Cortefy(
    api_key=os.environ.get("CORTEFY_API_KEY"),
    base_url="https://api.cortefy.com"  # Optional, defaults to localhost
)

# Add a memory
result = client.memories.add(
    content="Machine learning enables computers to learn from data",
    container_tag="ai-research",
    metadata={"priority": "high", "source": "research-paper"},
    custom_id="doc_2024_01_research_ml"
)

# Upload a file
result = client.memories.upload_file(
    file_path="./document.pdf",
    container_tags="research"
)

# Search memories (single container)
results = client.search.memories(
    q="machine learning accuracy",
    limit=5,
    container_tag="ai-research"
)

# Search across multiple containers
results = client.search.memories(
    q="machine learning accuracy",
    container_tags=["ai-research", "notes", "docs"]
)

API Reference

Cortefy Client

client = Cortefy(api_key: str, base_url: Optional[str] = None)
  • api_key: Your Cortefy API key (required)
  • base_url: Base URL for the API (defaults to http://localhost:8000)

Memories Resource

client.memories.add(...)

Add a memory to the Cortefy API.

Parameters:

  • content (str, required): The text content to store
  • container_tag (str, optional): Single container tag/name (recommended, preferred over container_tags)
  • container_tags (List[str] or str, optional): Container tag(s) - deprecated, use container_tag
  • metadata (dict, optional): Optional metadata dictionary (values must be strings, numbers, or booleans)
  • custom_id (str, optional): Custom identifier for deduplication and updates (max 255 chars)
  • raw (str, optional): Raw content to store alongside processed content
  • chunk_method (str, optional): Chunking method ('tokens' or 'sentences', default: 'tokens')
  • chunk_size (int, optional): Size of chunks (default: 1000)
  • chunk_overlap (int, optional): Overlap between chunks (default: 200)

Returns: Response dict with status, chunks, memory_ids, container, and timing

client.memories.upload_file(...)

Upload a file and process it into memories.

Parameters:

  • file_path (str, required): Path to the file to upload
  • container_tags (str, optional): Container tag for the uploaded file
  • container_tag (str, optional): Container tag (alternative to container_tags)

Supported formats:

  • Documents: PDF, DOC, DOCX, TXT, MD
  • Images: JPG, PNG, GIF, WebP (requires OCR libraries: Pillow, pytesseract)
  • Videos: MP4, WebM, AVI (not yet supported)

Maximum file size: 50MB

Returns: Response dict with status, chunks, memory_ids, container, filename, and timing

Search Resource

client.search.memories(...)

Search memories using semantic search.

Parameters:

  • q (str, required): Search query text
  • container_tag (str or List[str], optional): Single container tag to filter by (deprecated: use container_tags)
  • container_tags (List[str], optional): List of container tags to search across multiple containers
  • limit (int, optional): Maximum number of results (default: 5)
  • min_similarity (float, optional): Minimum similarity score 0.0-1.0 (default: 0.0)

Returns: Response dict with results, timing, and total

Error Handling

The client raises custom exceptions:

  • CortefyException: Base exception for all Cortefy errors
  • AuthenticationError: Raised when API key authentication fails
  • APIError: Raised when API returns an error response
  • ValidationError: Raised when request validation fails
from cortefy import Cortefy
from cortefy.exceptions import AuthenticationError, APIError

try:
    client = Cortefy(api_key="invalid-key")
    result = client.memories.add(content="test")
except AuthenticationError as e:
    print(f"Auth failed: {e}")
except APIError as e:
    print(f"API error: {e} (status: {e.status_code})")

License

MIT

Links

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

cortefy-0.1.4.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cortefy-0.1.4-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file cortefy-0.1.4.tar.gz.

File metadata

  • Download URL: cortefy-0.1.4.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for cortefy-0.1.4.tar.gz
Algorithm Hash digest
SHA256 1da354de00dac5a88754527427d52f9aa8a9a193744da6c445b4359ae4fddef0
MD5 5b5b2f450712ee341d8e6ef6339b1935
BLAKE2b-256 54b84ac5d5c7f9d97e15780450cbba771928fe5319b1cc4c497a7189b653492c

See more details on using hashes here.

File details

Details for the file cortefy-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: cortefy-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for cortefy-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a2bb0f6f95af4a9d8c783bf2922a0b7f96c34587e5eac2639f1993f829e9c9c9
MD5 ff8fad678ad806170969b7c12bf5b5f5
BLAKE2b-256 ad9214034905f536aefecd3c3f27e7727bc06b123cb5aeac81d3b536f391d5ce

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