Skip to main content

The official Python SDK for the Cortex AI platform.

Project description

Cortex AI Python SDK - usecortex.ai

The official Python SDK for the Cortex AI platform. Build powerful, context-aware AI applications in your Python applications.

Cortex is your plug-and-play memory infrastructure. It powers intelligent, context-aware retrieval for any AI app or agent. Whether you’re building a customer support bot, research copilot, or internal knowledge assistant.

Learn more about the SDK from our docs

Core features

  • Dynamic retrieval and querying that always retrieve the most relevant context
  • Built-in long-term memory that evolves with every user interaction
  • Personalization hooks for user preferences, intent, and history
  • Developer-first SDK with the most flexible APIs and fine-grained controls

Getting started

Installation

pip install usecortex-ai

Client setup

We provide both synchronous and asynchronous clients. Use AsyncCortexAI when working with async/await patterns, and CortexAI for traditional synchronous workflows. Client initialization does not trigger any network requests, so you can safely create as many client instances as needed. Both clients expose the exact same set of methods.

import os
from usecortex_ai import CortexAI, AsyncCortexAI

api_key = os.environ["CORTEX_API_KEY"]  # Set your Cortex API key in the environment variable CORTEX_API_KEY. Optional, but recommended.

# Sync client
client = CortexAI(token=api_key)

# Async client (for async/await usage)
async_client = AsyncCortexAI(token=api_key)

Create a Tenant

You can consider a tenant as a single database that can have internal isolated collections called sub-tenants. Know more about the concept of tenant here

def create_tenant():
    return client.user.create_tenant(tenant_id="my-company")

Index Your Data

When you index your data, you make it ready for retrieval from Cortex using natural language.

# Upload text content
def upload_text():
    return client.upload.upload_text(
        tenant_id="my-company-py-sync",
        sub_tenant_id="engineering",
        content="Our API rate limits are 1000 requests per minute for premium accounts.",
        file_id="api-docs-rate-limits",
        tenant_metadata={"sub_tenant_id": "engineering"}
    )

# Upload document file
def upload_file():
    with open("company-handbook.pdf", 'rb') as file_obj:
        file_data = ("company-handbook.pdf", file_obj)
        return client.upload.upload_document(
            tenant_id="my-company",
            file=file_data,
            file_id="company-handbook.pdf"
        )

For a more detailed explanation of document upload, including supported file formats, processing pipeline, metadata handling, and advanced configuration options, refer to the Upload Document endpoint documentation.

Search and retrieval

# Semantic search with retrieval
results = client.search.retrieve(
    query="What are the API rate limits?",
    tenant_id="my-company",
    sub_tenant_id="engineering",
    max_chunks=10
)

# List all sources
all_sources = client.sources.get_all(
    tenant_id="my-company",
    sub_tenant_id="engineering",
)

# Get specific sources by ID
specific_sources = client.sources.get_by_ids(
    tenant_id="my-company",
    sub_tenant_id="engineering",
    source_ids=["api-docs-rate-limits", "company-handbook"]
)

For a more detailed explanation of search and retrieval, including query parameters, scoring mechanisms, result structure, and advanced search features, refer to the Search endpoint documentation.

SDK Method Structure & Type Safety

Our SDKs follow a predictable pattern that mirrors the API structure while providing full type safety.

Method Mapping : client.<group>.<function_name> mirrors api.usecortex.ai/<group>/<function_name>

For example: client.upload.upload_text() corresponds to POST /upload/upload_text

The SDKs provide exact type parity with the API specification:

  • Request Parameters : Every field documented in the API reference (required, optional, types, validation rules) is reflected in the SDK method signatures
  • Response Objects : Return types match the exact JSON schema documented for each endpoint
  • Error Types : Exception structures mirror the error response formats from the API
  • Nested Objects : Complex nested parameters and responses maintain their full structure and typing

This means you can rely on your IDE’s autocomplete and type checking. If a parameter is optional in the API docs, it’s optional in the SDK. If a response contains a specific field, your IDE will know about it. Our SDKs are built in such a way that your IDE will automatically provide autocompletion, type-checking, inline documentation with examples, and compile time validation for each and every method.

Just hit Cmd+Space/Ctrl+Space!

Links

Our docs

Please refer to our API reference for detailed explanations of every API endpoint, parameter options, and advanced use cases.

Support

If you have any questions or need help, please reach out to our support team at founders@usecortex.ai.

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

usecortex_ai-0.3.6.tar.gz (69.1 kB view details)

Uploaded Source

Built Distribution

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

usecortex_ai-0.3.6-py3-none-any.whl (119.9 kB view details)

Uploaded Python 3

File details

Details for the file usecortex_ai-0.3.6.tar.gz.

File metadata

  • Download URL: usecortex_ai-0.3.6.tar.gz
  • Upload date:
  • Size: 69.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for usecortex_ai-0.3.6.tar.gz
Algorithm Hash digest
SHA256 4cf2f6eb5cc1f1f9431dd5fce9296a6d4ad24d222dc766965c5cfeb3a9db9894
MD5 52d459871315bee9510389532de788b2
BLAKE2b-256 62a42cc96e9aea2eea998f18ed61caf2dcfa18364a0e3655746543612c9b6f24

See more details on using hashes here.

File details

Details for the file usecortex_ai-0.3.6-py3-none-any.whl.

File metadata

  • Download URL: usecortex_ai-0.3.6-py3-none-any.whl
  • Upload date:
  • Size: 119.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for usecortex_ai-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 3e039821048be4b255ce060555dd5d82c268b22b9c67ec112a622106e26dc897
MD5 3f6006845b76c1becbb36b9c91dea241
BLAKE2b-256 b731f0b84b7d682d4ea4e25a38d6a1f15e4e1bd13f71b315488bcf4dc13fae9c

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