All Products
Search
Document Center

Tablestore:Memulai Cepat

Last Updated:May 22, 2026

Gunakan CLI, Python SDK, atau Node.js SDK untuk menyelesaikan alur kerja end-to-end dalam waktu sekitar 10 menit: buat penyimpanan memori, tulis percakapan, cari memori jangka panjang, dan lihat memori jangka pendek.

Prasyarat

Sebelum memulai, pastikan Anda telah memenuhi persyaratan berikut:

  • Instans Tablestore, termasuk titik akhir (endpoint) dan nama instansnya.

    Catatan

    Fitur ini saat ini hanya tersedia di Wilayah China (Beijing).

  • Kredensial Anda (ID AccessKey dan AccessKey Secret) untuk mengakses instans tersebut.

  • Python SDK, Node.js SDK, atau Tablestore Agent Storage CLI.

CLI

Instal CLI

npm install -g @tablestore/tablestore-agent-cli
tablestore-agent-cli version

Konfigurasikan kredensial

tablestore-agent-cli configure set access_key_id '...'
tablestore-agent-cli configure set access_key_secret '...'
tablestore-agent-cli configure set region 'cn-beijing'

Jika Anda sudah memiliki instans Tablestore, Anda juga dapat mengonfigurasi titik akhir dan nama instansnya:

tablestore-agent-cli configure set ots_endpoint 'https://<instance>.cn-beijing.ots.aliyuncs.com'
tablestore-agent-cli configure set ots_instance_name '<instance-name>'

Jika Anda tidak mengonfigurasi ots_endpoint dan ots_instance_name, CLI akan secara otomatis membuat dan menggunakan kembali instans Tablestore terkelola sesuai kebutuhan.

Diagnosis konfigurasi

tablestore-agent-cli doctor memory

Buat penyimpanan memori

tablestore-agent-cli memory create --store agent_memory --description "Agent long-term memory store"

Setelah penyimpanan memori dibuat, indeks memerlukan waktu untuk diinisialisasi. Disarankan untuk menunggu sekitar satu menit sebelum menulis atau mencari memori.

Tambahkan memori

tablestore-agent-cli memory add \
  --store agent_memory \
  --app-id app-001 \
  --tenant-id user-001 \
  --agent-id assistant \
  --run-id session-001 \
  --text "The user likes coffee and prefers concise responses." \
  --sync

Parameter --sync membuat perintah menunggu hingga ekstraksi memori selesai sebelum mengembalikan respons. Di lingkungan produksi, Anda dapat menghilangkan parameter ini untuk menggunakan penulisan asinkron bawaan.

Cari memori jangka panjang

tablestore-agent-cli memory search \
  --store agent_memory \
  --app-id app-001 \
  --tenant-id user-001 \
  --agent-id '*' \
  --run-id '*' \
  --query "What does the user like to drink?" \
  --top-k 5

Saat mencari memori jangka panjang, appId dan tenantId wajib diisi. Anda dapat menggunakan tanda bintang (*) untuk agentId dan runId guna mencari lintas agen dan sesi.

Lihat memori jangka pendek

tablestore-agent-cli memory msg-list \
  --store agent_memory \
  --app-id app-001 \
  --tenant-id user-001 \
  --agent-id assistant \
  --run-id session-001

API memori jangka pendek melakukan kueri terhadap pesan sesi mentah dan memerlukan keempat level cakupan (appId, tenantId, agentId, dan runId). Karakter wildcard (*) tidak diperbolehkan.

Python SDK

Instal SDK

pip install "tablestore>=6.4.5"

Kode contoh

from tablestore import OTSClient

client = OTSClient(
    "https://<instance>.cn-beijing.ots.aliyuncs.com",
    "<AccessKey ID>",
    "<AccessKey Secret>",
    "<instance-name>",
)

client.create_memory_store({
    "memoryStoreName": "agent_memory",
    "description": "Agent long-term memory store",
})

client.add_memories({
    "memoryStoreName": "agent_memory",
    "scope": {
        "appId": "app-001",
        "tenantId": "user-001",
        "agentId": "assistant",
        "runId": "session-001",
    },
    "messages": [
        {"role": "user", "content": "I like coffee"},
        {"role": "assistant", "content": "Okay, I will remember that"},
    ],
    "sync": True,
})

result = client.search_memories({
    "memoryStoreName": "agent_memory",
    "scope": {
        "appId": "app-001",
        "tenantId": "user-001",
        "agentId": "*",
        "runId": "*",
    },
    "query": "What does the user like to drink?",
    "topK": 5,
})

for item in result.get("results", []):
    print(item["unit"]["text"], item["score"])

Node.js SDK

Instal SDK

npm install tablestore@^5.6.5

Kode contoh

const TableStore = require("tablestore");

const client = new TableStore.Client({
  accessKeyId: "<AccessKey ID>",
  secretAccessKey: "<AccessKey Secret>",
  endpoint: "https://<instance>.cn-beijing.ots.aliyuncs.com",
  instancename: "<instance-name>",
});

async function main() {
  await client.createMemoryStore({
    memoryStoreName: "agent_memory",
    description: "Agent long-term memory store",
  });

  await client.addMemories({
    memoryStoreName: "agent_memory",
    scope: {
      appId: "app-001",
      tenantId: "user-001",
      agentId: "assistant",
      runId: "session-001",
    },
    text: "The user likes coffee and prefers concise responses.",
    sync: true,
  });

  const result = await client.searchMemories({
    memoryStoreName: "agent_memory",
    scope: {
      appId: "app-001",
      tenantId: "user-001",
      agentId: "*",
      runId: "*",
    },
    query: "What does the user like to drink?",
    topK: 5,
  });

  for (const item of result.results || []) {
    console.log(item.unit.text, item.score);
  }
}

main().catch(console.error);

Dokumentasi terkait