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 baselist_knowledge_base(request)- List all knowledge basesdescribe_knowledge_base(request)- Get knowledge base detailsupdate_knowledge_base(request)- Update knowledge base description/tags/retrieval configdelete_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 bydocIdorossKeylist_documents(request)- List documents in knowledge baseget_document(request)- Get document detailsdelete_documents(request)- Delete documents
Chunk Operations
list_chunks(request)- List chunks bydocId/ossKeywith pagination supportupdate_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 requires the following 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)oss_endpoint: OSS service endpointoss_bucket_name: OSS bucket nameots_endpoint: OTS service endpoint (optional)ots_instance_name: OTS instance name (optional)
Examples
See the examples/ directory for more detailed usage examples.
Dependencies
- Python >= 3.8
- oss2 >= 2.18.0
- tablestore >= 6.4.3
Contact
Release files for tablestore-agent-storage 1.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tablestore_agent_storage-1.0.7.tar.gz | 21.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tablestore_agent_storage-1.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 43.0 kB
Release files / tablestore_agent_storage-1.0.7.tar.gz
| Download URL | tablestore_agent_storage-1.0.7.tar.gz |
|---|---|
| Size | 21.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
06be18b7c8f3c664551d30800a9a74c00fb0d688242bb353766a7d6b0c3ccabf
|
|
BLAKE2b-256 checksum How to use checksums |
6fe198a1c8da5e731f04989ae705b9e88eb5bd86d5dd4e9794eddda942c4989c
|
| 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.7-py3-none-any.whl
| Download URL | tablestore_agent_storage-1.0.7-py3-none-any.whl |
|---|---|
| Size | 21.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
22f90c5c8c369b4f74ccce70f7b606d9147dc2f11d7c17302096b5176ca036c6
|
|
BLAKE2b-256 checksum How to use checksums |
4d421a43fadbfa95b0dc88f8df5388264812a3d26e4389db839d756b57715bd0
|
| 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
|