agentleFS
CohereKnown publishercohere-ai/cohere-compass-sdk/AGENTS.md

cohere-compass-sdk

AGENTS.md13 starsChanged 2 days agoMITView on GitHub

Cohere Compass SDK is a Python library for parsing documents and interacting with a Compass index. It targets Python >=3.11 and is managed with Poetry. The package name is cohere-compass-sdk (importable as cohere_compass). The SDK provides two main sets of client classes: - CompassClient / CompassAsyncClient -- synchronous and asynchronous clients for the Compass index API (CRUD, search, RBAC) - CompassParserClient / CompassParserAsyncClient -- synchronous and asynchronous clients for the Compass Parser API (document parsing) - CompassRootClient -- synchronous client…

  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.

    Of the AGENTS.md files we read, the 31,439 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

18 rules. About 0 are common, 3 are distinctive, and 15 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 15

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    All HTTP calls are wrapped with handle_httpx_exceptions() from exceptions.py, which converts httpx errors to typed Compass exceptions

    line 100
  2. Very specific:

    Default timeouts are defined in constants.py per client type

    line 102
  3. Very specific:

    All data models are Pydantic v2 models.

    line 121
  4. Very specific:

    Import sorting identifies cohere_compass as first-party.

    line 149
  5. Distinctive:

    All HTTP tests use respx for mocking (no integration tests against a real server).

    line 159
  6. Very specific:

    Test utilities in tests/utils.py: create_test_doc() factory, SyncifiedCompassAsyncClient adapter.

    line 163
  7. Very specific:

    Every PR that modifies cohere_compass/ or pyproject.toml must bump the version in pyproject.toml.

    line 166
  8. Very specific:

    All files are owned by @cohere-ai/compass.

    line 173
  9. Very specific:

    Add the endpoint to the API_DEFINITIONS dict in cohere_compass/clients/compass.py

    line 204
  10. Very specific:

    Add a method to CompassClient that calls _send_request() with the new API name

    line 205
  11. Very specific:

    Add the equivalent async method to CompassAsyncClient (using await _send_request())

    line 206
  12. Very specific:

    Add Pydantic request/response models in cohere_compass/models/ if needed

    line 207
  13. Very specific:

    Add tests using mock_endpoint decorator in test_compass_client.py (parametrized for sync/async)

    line 208
  14. Very specific:

    Create or edit the appropriate file in cohere_compass/models/

    line 212
  15. Distinctive:

    Add tests for the model

    line 215
  16. Very specific:

    Add to cohere_compass/exceptions.py, inheriting from the appropriate base (CompassError, CompassNetworkError, CompassClientError, etc.)

    line 218
  17. Very specific:

    Update handle_httpx_exceptions() if the exception should be auto-raised from HTTP errors

    line 219
  18. Distinctive:

    Add tests verifying the exception is raised in the correct scenarios

    line 220

≈ “Common” is an estimate: at least 1 in 5 of the 40,246 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

AGENTS.md

Project Overview

Cohere Compass SDK is a Python library for parsing documents and interacting with a Compass index. It targets Python >=3.11 and is managed with Poetry. The package name is cohere-compass-sdk (importable as cohere_compass).

The SDK provides two main sets of client classes:

  • CompassClient / CompassAsyncClient -- synchronous and asynchronous clients for the Compass index API (CRUD, search, RBAC)
  • CompassParserClient / CompassParserAsyncClient -- synchronous and asynchronous clients for the Compass Parser API (document parsing)
  • CompassRootClient -- synchronous client for RBAC (Role-Based Access Control) administration

Commands

Install dependencies

poetry install

Run tests

poetry run pytest -sv

Run linting and formatting

poetry run ruff check --fix .
poetry run ruff format .

Run type checking

poetry run pyright

Run pre-commit hooks manually

pre-commit run --all-files

Install pre-commit hooks (local dev setup)

poetry run pre-commit install

Repository Structure

cohere-compass-sdk/
  cohere_compass/                    # Main SDK package
    __init__.py                      # Package version, legacy param models (ProcessFileParameters, GroupAuthorizationInput, etc.)
    constants.py                     # Default configs, timeouts, retry settings, regex patterns
    exceptions.py                    # Exception hierarchy + httpx-to-Compass exception mapper
    models/                          # Pydantic data models
      __init__.py                    # ValidatedModel base class, re-exports
      access_control.py              # RBAC models: User, Role, Group, Policy, Pagination
      config.py                      # ParserConfig, EnrichmentConfig, IndexConfig, strategy enums
      documents.py                   # CompassDocument, chunks, upload/download models, ContentTypeEnum
      enrichments.py                 # Webhook enrichment request/response models
      indexes.py                     # IndexInfo, IndexDetails, RetentionPolicy
      search.py                      # SearchInput, SearchFilter, RetrievedChunk/Document, DirectSearchInput
    clients/                         # API client implementations
      __init__.py                    # Re-exports all 5 client classes
      compass.py                     # CompassClient (sync) -- index CRUD, document ops, search, assets
      compass_async.py               # CompassAsyncClient (async) -- mirrors CompassClient
      parser.py                      # CompassParserClient (sync) -- file/folder parsing
      parser_async.py                # CompassParserAsyncClient (async) -- mirrors CompassParserClient
      access_control.py              # CompassRootClient (sync) -- RBAC admin
    utils/                           # Internal utility modules
      __init__.py
      asyn.py                        # async_enumerate, async_map, async_apply
      documents.py                   # generate_doc_id_from_bytes, partition_documents, partition_documents_async
      fs.py                          # get_fs, open_document, scan_folder (fsspec-based)
      iter.py                        # imap_parallel (bounded parallel map)
      retry.py                       # is_retryable_httpx_exception, is_retryable_compass_exception
    ext/                             # Optional extensions; one extra per extension, plus `all`
      uploads/                       # Resumable directory/gs:// uploads: discovery, content IDs, pruning, job stores
    py.typed                         # PEP 561 marker
  tests/                             # Test suite
    test_compass_client.py           # CompassClient + CompassAsyncClient tests (parametrized sync/async)
    test_parser_client.py           # CompassParserClient tests
    test_access_control.py           # CompassRootClient RBAC tests
    test_context_management.py       # Context manager and resource cleanup tests for all 4 main clients
    test_utils.py                    # Tests for utils: asyn, iter, fs, documents
    utils.py                         # Test helpers: create_test_doc, SyncifiedCompassAsyncClient
    docs/                            # Sample test documents (pdf, docx, xlsx, etc.)
  examples/                          # Standalone Poetry project with example scripts
  .github/workflows/                 # CI: test.yml, pre-commit-checks.yml, lint-pr.yaml, check-version-bump.yml, autogenerate-release.yml
  pyproject.toml                     # Project config, dependencies, tool settings
  poetry.toml                        # Poetry local config (in-project venv)
  .pre-commit-config.yaml            # Ruff + Pyright hooks

Architecture

Client Design Pattern

Each client wraps an httpx.Client (sync) or httpx.AsyncClient (async) and follows a consistent pattern:

  • Constructor accepts compass_url/index_url/parser_url, optional bearer_token, timeout, and optional externally-owned httpx_client
  • Clients track ownership of the httpx client (_own_httpx_client flag) -- they only close clients they created
  • All HTTP calls are wrapped with handle_httpx_exceptions() from exceptions.py, which converts httpx errors to typed Compass exceptions
  • Retry logic uses tenacity with is_retryable_httpx_exception (for raw httpx errors in Compass clients) or is_retryable_compass_exception (for already-converted errors in Parser clients)
  • Default timeouts are defined in constants.py per client type

Sync/Async Parity

CompassClient and CompassAsyncClient share the same API_DEFINITIONS dict (defined in compass.py, imported by compass_async.py). They have identical public APIs. CompassParserClient and CompassParserAsyncClient similarly mirror each other. The async versions use async_apply/async_map from utils/asyn.py instead of imap_parallel/joblib.Parallel.

Error Handling (V2 Breaking Change)

V2+ uses exception-based error handling. All HTTP errors are converted via handle_httpx_exceptions():

  • httpx.TimeoutException -> CompassTimeoutError
  • httpx.NetworkError -> CompassNetworkError
  • 401/403 -> CompassAuthError
  • Other 4xx -> CompassClientError
  • 5xx -> CompassServerError
  • CompassInsertionError for batch insertion failures
  • CompassMaxErrorRateExceeded for sliding-window error rate thresholds

Models

All data models are Pydantic v2 models. ValidatedModel (in models/__init__.py) extends BaseModel with attribute-name validation and arbitrary_types_allowed/use_enum_values config. Models are organized by domain: access_control.py, config.py, documents.py, enrichments.py, indexes.py, search.py.

Document Batch Insertion

CompassClient.insert_docs() uses partition_documents() from utils/documents.py to split documents into request-sized chunks (respecting max_chunks_per_request). It tracks errors with a sliding window and supports parallel insertion via joblib.Parallel.

Extensions

cohere_compass/ext/ holds optional, higher-level features built on the clients, following the ext convention of SQLAlchemy and Sphinx. The core SDK (clients, models, utils) never imports from ext. Each extension that needs dependencies beyond the core gets its own extra in pyproject.toml, named after the extension (for example uploads), and its dependencies are also added to the all extra. Extensions may be async-only.

An extension never decides where to persist state on its own. The uploads extension takes an UploadJobStore from the caller (SqliteUploadJobStore(path), FileUploadJobStore(directory) or InMemoryUploadJobStore), and reports progress through an UploadReporter whose methods are all no-ops by default. Terminal UI belongs to callers.

Document Parsing Pipeline

CompassParserClient.process_file() -> opens file via utils/fs.py -> sends bytes to parser API -> deserializes response into CompassDocument objects. process_folder() scans via fsspec, then processes in parallel using imap_parallel.

Code Conventions

Style and Formatting

  • Ruff is the linter and formatter. Line length is 120 (root project) / 88 (examples).
  • Target Python 3.10+ for Ruff rules, but project requires >=3.11.
  • Rules: mccabe (max complexity 15), pydocstyle, pycodestyle, isort, flake8-quotes, Ruff-specific, pyupgrade.
  • Ignored docstring rules: D100, D104, D212 (root); D100, D103, D104, D200, D212 (examples).
  • Import sorting identifies cohere_compass as first-party.

Type Checking

  • Pyright in strict mode.
  • reportMissingImports is suppressed.
  • Tests use # pyright: reportPrivateUsage=false when accessing private attributes.

Testing

  • pytest with pytest-asyncio and pytest-cov.
  • 80% branch coverage minimum is enforced.
  • All HTTP tests use respx for mocking (no integration tests against a real server).
  • Sync/async parity is tested via SyncifiedCompassAsyncClient (in tests/utils.py) which wraps async methods with asyncio.run().
  • The client fixture in test_compass_client.py is parametrized to run every test against both sync and async clients.
  • mock_endpoint decorator (in test_compass_client.py) provides declarative HTTP mock setup.
  • Test utilities in tests/utils.py: create_test_doc() factory, SyncifiedCompassAsyncClient adapter.

Version Bumping

  • Every PR that modifies cohere_compass/ or pyproject.toml must bump the version in pyproject.toml.
  • A CI check (check-version-bump.yml) enforces this. PRs can be exempted with a skip-version-check label.

Commit Conventions

  • PR titles must follow Conventional Commits (e.g., feat:, fix:, docs:), enforced by lint-pr.yaml.

Code Ownership

  • All files are owned by @cohere-ai/compass. All PRs require approval from this team.

Key Dependencies

DependencyPurpose
httpxHTTP client (sync + async)
pydantic v2Data models and validation
tenacityRetry logic with configurable backoff
fsspecFilesystem abstraction (local, S3, GCS)
joblibParallel batch document insertion

CI/CD

WorkflowTriggerWhat it does
test.ymlPush to main, PRs to mainRuns pytest -sv across Python 3.11 through 3.15
pre-commit-checks.ymlAll PRsRuns ruff + pyright across Python 3.11 through 3.15
lint-pr.yamlPR eventsEnforces semantic PR titles
check-version-bump.ymlPRs to mainBlocks PRs without version bump
autogenerate-release.ymlPush to main (pyproject.toml change)Auto-creates GitHub release + publishes to PyPI

Release Process

  1. Bump version in pyproject.toml
  2. Merge PR to main (must pass all CI checks)
  3. autogenerate-release.yml creates GitHub release tag and publishes to PyPI via Poetry

Common Tasks

Adding a new API endpoint to CompassClient

  1. Add the endpoint to the API_DEFINITIONS dict in cohere_compass/clients/compass.py
  2. Add a method to CompassClient that calls _send_request() with the new API name
  3. Add the equivalent async method to CompassAsyncClient (using await _send_request())
  4. Add Pydantic request/response models in cohere_compass/models/ if needed
  5. Add tests using mock_endpoint decorator in test_compass_client.py (parametrized for sync/async)
  6. Bump version in pyproject.toml

Adding a new model

  1. Create or edit the appropriate file in cohere_compass/models/
  2. Inherit from ValidatedModel (from models/__init__.py) or BaseModel (from pydantic) as appropriate
  3. Re-export from cohere_compass/models/__init__.py if needed
  4. Add tests for the model

Adding a new exception

  1. Add to cohere_compass/exceptions.py, inheriting from the appropriate base (CompassError, CompassNetworkError, CompassClientError, etc.)
  2. Update handle_httpx_exceptions() if the exception should be auto-raised from HTTP errors
  3. Add tests verifying the exception is raised in the correct scenarios

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.