Skip to main content

Aliyun Tablestore Agent Storage Python SDK

A Python SDK for agent storage with support for Aliyun OSS and OTS, featuring:

  • knowledge base management
  • document management
  • chunk-level listing and update
  • retrieval with metadata filters

Installation

pip install tablestore-agent-storage

or install from source:

pip install -e .

Quick Start

from tablestore_agent_storage import (
    AgentStorageClient,
    UpdateKnowledgeBaseRequest,
    UpdateDocumentRequest,
    ListChunksRequest,
    UpdateChunkItem,
    UpdateChunksRequest,
)

# Initialize client with unified credentials
client = AgentStorageClient(
    access_key_id='your_access_key_id',
    access_key_secret='your_access_key_secret',
    oss_endpoint='https://oss-cn-hangzhou.aliyuncs.com',
    oss_bucket_name='your_bucket_name',
    ots_endpoint='https://your_instance.cn-hangzhou.ots.aliyuncs.com',
    ots_instance_name='your_instance_name'
)

# Create a knowledge base
response = client.create_knowledge_base({
    'knowledgeBaseName': 'my_knowledge_base',
    'description': 'My first knowledge base'
})

# Update knowledge base
client.update_knowledge_base(
    UpdateKnowledgeBaseRequest(
        knowledge_base_name="my_knowledge_base",
        description="Updated description",
        tags=["production", "v2"]
    )
)

# Add a document with OSS key
client.add_documents({
    'knowledgeBaseName': 'my_knowledge_base',
    'documents': [{
        'ossKey': 'oss://your-bucket/path/to/file.pdf',
        'metadata': {'author': 'aliyun'}
    }]
})

# Or add a document by uploading a local file
client.upload_documents({
    'knowledgeBaseName': 'my_knowledge_base',
    'documents': [{
        'filePath': '/path/to/local/file.pdf',
        'metadata': {'author': 'aliyun'}
    }]
})

# Update document metadata
client.update_document(
    UpdateDocumentRequest(
        knowledge_base_name="my_knowledge_base",
        doc_id="doc_123",
        metadata={"author": "new_author"}
    )
)

# List chunks
chunk_list = client.list_chunks(
    ListChunksRequest(
        knowledge_base_name="my_knowledge_base",
        doc_id="doc_123",
        max_results=10
    )
)

# Update chunks
client.update_chunks(
    UpdateChunksRequest(
        knowledge_base_name="my_knowledge_base",
        chunks=[
            UpdateChunkItem(chunk_id=1, doc_id="doc_123", title="new title"),
            UpdateChunkItem(chunk_id=2, doc_id="doc_123", content="new content"),
        ],
    )
)

# Search/Retrieve
results = client.retrieve({
    'knowledgeBaseName': 'knowledgeBaseName',
    "retrievalQuery": {
        "text": "text to search",
        "type": "TEXT"
    }
})

API Reference

Knowledge Base Operations

  • create_knowledge_base(request) - Create new knowledge base
  • list_knowledge_base(request) - List all knowledge bases
  • describe_knowledge_base(request) - Get knowledge base details
  • update_knowledge_base(request) - Update knowledge base description/tags/retrieval config
  • delete_knowledge_base(request) - Delete knowledge base

Document Operations

  • add_documents(request) - Add a document to a knowledge base (requires OSS key)
  • upload_documents(request) - Add a document by uploading a local file (automatically uploads to OSS)
  • update_document(request) - Update document metadata by docId or ossKey
  • list_documents(request) - List documents in knowledge base
  • get_document(request) - Get document details
  • delete_documents(request) - Delete documents

Chunk Operations

  • list_chunks(request) - List chunks by docId/ossKey with pagination support
  • update_chunks(request) - Batch update chunk title/content/status

Retrieval Operations

  • retrieve(request) - Perform vector search/retrieval

Update Request Semantics

UpdateKnowledgeBaseRequest, UpdateDocumentRequest, and UpdateChunkItem use an internal UNSET sentinel:

  • field not provided: keep current value unchanged
  • field explicitly set to None: clear this field on server side

This makes partial update behavior explicit and predictable.

Configuration

The SDK supports API Key authentication or signed AK/STS requests. All Agent Storage requests are implemented inside this package and do not depend on the general Tablestore Python SDK exposing matching methods.

Core configuration parameters:

  • access_key_id: Your Aliyun access key ID (shared by OSS and OTS)
  • access_key_secret: Your Aliyun access key secret (shared by OSS and OTS)
  • sts_token: Optional STS security token
  • api_key: API Key for OTS requests; requires an HTTPS endpoint
  • oss_endpoint: OSS service endpoint
  • oss_bucket_name: OSS bucket name
  • ots_endpoint: OTS service endpoint
  • ots_instance_name: OTS instance name

Additional keyword options remain available:

  • credentials_provider: Refreshing provider with a get_credentials() method
  • region: Enables SignV4 for the specified region; SignV2 is the default
  • sign_version: Explicitly select v2 or v4
  • socket_timeout: Per-request timeout in seconds
  • max_connection: HTTP connection-pool size
  • ssl_version: Minimum TLS version
  • extra_headers: Headers attached to every OTS request
  • retry_policy: Object implementing should_retry() and get_retry_delay()

Examples

See the examples/ directory for more detailed usage examples.

Dependencies

  • Python >= 3.8
  • oss2 >= 2.18.0
  • urllib3 >= 1.26, < 3

Contact

Release files for tablestore-agent-storage 1.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tablestore-agent-storage 1.0.9
File Size Uploaded
tablestore_agent_storage-1.0.9.tar.gz 33.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tablestore-agent-storage 1.0.9
File Interpreter ABI Platform
tablestore_agent_storage-1.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 61.6 kB

Release files / tablestore_agent_storage-1.0.9.tar.gz

Download URL tablestore_agent_storage-1.0.9.tar.gz
Size 33.6 kB
Tags Source
SHA-256 checksum
How to use checksums
78c6943b3123f551d0252a6554a72762a7d0e8d3619cc4abc20776a6841707a8
BLAKE2b-256 checksum
How to use checksums
7a8b6cc19c140761f61b8f2b793e6d63404cf3199c213d4b266fa2f6f3fdc8a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.9.19 Linux/5.10.134-010.ali5000.al8.x86_64

Release files / tablestore_agent_storage-1.0.9-py3-none-any.whl

Download URL tablestore_agent_storage-1.0.9-py3-none-any.whl
Size 28.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
703e1b71771c389af4a21e6cb1d73acca328cddcbde8ca30026a182f2da864f9
BLAKE2b-256 checksum
How to use checksums
dfef5a03880cbc42b48d628d2166b2de4cf6d653d04844629dfdbfcf7ad82ada
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.9.19 Linux/5.10.134-010.ali5000.al8.x86_64

Release history Release notifications | RSS feed

1.0.10

2 release files

This release

1.0.9 This release

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page