tavus-cvi-knowledge

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Tavus CVI Knowledge Base & Memories

Tavus CVI 知识库与记忆功能

Give your personas access to documents and persistent memory.
让你的角色能够访问文档并拥有持久化记忆。

Knowledge Base (RAG)

知识库(RAG)

Upload documents that personas can reference during conversations.
上传可供角色在对话中参考的文档。

Step 1: Create Document

步骤1:创建文档

bash
curl -X POST https://tavusapi.com/v2/documents \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{
    "document_name": "Product FAQ",
    "document_url": "https://example.com/faq.pdf",
    "tags": ["support", "faq"]
  }'
Response:
json
{
  "document_id": "d1234567890",
  "status": "processing"
}
bash
curl -X POST https://tavusapi.com/v2/documents \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{
    "document_name": "Product FAQ",
    "document_url": "https://example.com/faq.pdf",
    "tags": ["support", "faq"]
  }'
响应:
json
{
  "document_id": "d1234567890",
  "status": "processing"
}

Supported Sources

支持的数据源

  • PDFs: Direct URL to PDF file
  • Text files: Plain text documents
  • Websites: Single page or crawled
  • PDFs: 直接提供PDF文件的URL
  • Text files: 纯文本文档
  • Websites: 单页或可爬取的网站

Website Crawling

网站爬取

Single page (default):
json
{
  "document_name": "Landing Page",
  "document_url": "https://example.com/features"
}
Multi-page crawl:
json
{
  "document_name": "Full Docs",
  "document_url": "https://docs.example.com",
  "crawl_pages": true
}
单页爬取(默认):
json
{
  "document_name": "Landing Page",
  "document_url": "https://example.com/features"
}
多页爬取:
json
{
  "document_name": "Full Docs",
  "document_url": "https://docs.example.com",
  "crawl_pages": true
}

Step 2: Use in Conversation

步骤2:在对话中使用

By document IDs:
json
{
  "persona_id": "p123",
  "replica_id": "r456",
  "document_ids": ["d1234567890", "d0987654321"]
}
By tags:
json
{
  "persona_id": "p123",
  "replica_id": "r456",
  "document_tags": ["support", "faq"]
}
通过文档ID:
json
{
  "persona_id": "p123",
  "replica_id": "r456",
  "document_ids": ["d1234567890", "d0987654321"]
}
通过标签:
json
{
  "persona_id": "p123",
  "replica_id": "r456",
  "document_tags": ["support", "faq"]
}

Attach to Persona (Always Available)

绑定到角色(始终可用)

Documents available in ALL conversations with this persona:
bash
curl -X POST https://tavusapi.com/v2/personas \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{
    "persona_name": "Support Agent",
    "pipeline_mode": "full",
    "system_prompt": "You are a helpful support agent...",
    "document_ids": ["d1234567890"],
    "document_tags": ["support"]
  }'
绑定后,该文档将在与该角色的所有对话中可用:
bash
curl -X POST https://tavusapi.com/v2/personas \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{
    "persona_name": "Support Agent",
    "pipeline_mode": "full",
    "system_prompt": "You are a helpful support agent...",
    "document_ids": ["d1234567890"],
    "document_tags": ["support"]
  }'

Retrieval Strategy

检索策略

Optimize search speed vs quality:
json
{
  "persona_id": "p123",
  "document_ids": ["d123"],
  "retrieval_strategy": "balanced"
}
Options:
  • speed
    - Fastest, good for simple lookups
  • quality
    - Best results, slower
  • balanced
    - Default, good tradeoff
在搜索速度与质量间取得平衡:
json
{
  "persona_id": "p123",
  "document_ids": ["d123"],
  "retrieval_strategy": "balanced"
}
可选策略:
  • speed
    - 速度最快,适合简单查询
  • quality
    - 结果最佳,速度较慢
  • balanced
    - 默认选项,兼顾速度与质量

Manage Documents

管理文档

bash
undefined
bash
undefined

List documents

列出所有文档

curl https://tavusapi.com/v2/documents
-H "x-api-key: YOUR_API_KEY"
curl https://tavusapi.com/v2/documents
-H "x-api-key: YOUR_API_KEY"

Get document status

获取文档状态

curl https://tavusapi.com/v2/documents/{document_id}
-H "x-api-key: YOUR_API_KEY"
curl https://tavusapi.com/v2/documents/{document_id}
-H "x-api-key: YOUR_API_KEY"

Delete document

删除文档

curl -X DELETE https://tavusapi.com/v2/documents/{document_id}
-H "x-api-key: YOUR_API_KEY"

---
curl -X DELETE https://tavusapi.com/v2/documents/{document_id}
-H "x-api-key: YOUR_API_KEY"

---

Memories (Persistent Context)

记忆功能(持久化上下文)

Remember information across conversations with the same user.
在与同一用户的多次对话间保留信息。

How It Works

工作原理

  1. Assign a
    memory_store
    key to a conversation
  2. Persona forms memories during conversation
  3. Future conversations with same key access those memories
  1. 为对话分配一个
    memory_store
    密钥
  2. 角色在对话过程中形成记忆
  3. 使用同一密钥的后续对话可访问这些记忆

Create Conversation with Memory

创建带记忆功能的对话

json
{
  "persona_id": "p123",
  "replica_id": "r456",
  "memory_stores": ["user_alice_persona_sales"]
}
json
{
  "persona_id": "p123",
  "replica_id": "r456",
  "memory_stores": ["user_alice_persona_sales"]
}

Memory Store Naming

记忆存储命名规则

Use consistent, unique identifiers:
  • user_{user_id}_persona_{persona_id}
    - Per user, per persona
  • user_{user_id}
    - Per user across personas
  • session_{session_id}
    - Per session
Important: Don't use persona names in keys (they might change).
使用一致且唯一的标识符:
  • user_{user_id}_persona_{persona_id}
    - 按用户+角色划分
  • user_{user_id}
    - 跨角色的用户专属存储
  • session_{session_id}
    - 按会话划分
注意:不要在密钥中使用角色名称(角色名称可能会变更)。

Example: Returning User

示例:回访用户

First conversation:
json
{
  "persona_id": "p_coach",
  "memory_stores": ["user_alice_coaching"]
}
User mentions: "I'm training for a marathon in April."
Second conversation (days later):
json
{
  "persona_id": "p_coach", 
  "memory_stores": ["user_alice_coaching"]
}
Persona remembers the marathon goal and can reference it.
首次对话:
json
{
  "persona_id": "p_coach",
  "memory_stores": ["user_alice_coaching"]
}
用户提到:“我正在为四月的马拉松训练。”
后续对话(几天后):
json
{
  "persona_id": "p_coach", 
  "memory_stores": ["user_alice_coaching"]
}
角色会记住用户的马拉松目标并可在对话中提及。

Multiple Memory Stores

多记忆存储

Share memories across contexts:
json
{
  "persona_id": "p123",
  "memory_stores": [
    "user_alice_global",
    "user_alice_sales_specific"
  ]
}
跨上下文共享记忆:
json
{
  "persona_id": "p123",
  "memory_stores": [
    "user_alice_global",
    "user_alice_sales_specific"
  ]
}

Use Case: Multi-Persona Memory

用例:多角色共享记忆

User talks to Sales persona, then Support persona:
json
// Sales conversation
{
  "persona_id": "p_sales",
  "memory_stores": ["user_alice"]
}

// Support conversation (later)
{
  "persona_id": "p_support",
  "memory_stores": ["user_alice"]
}
Support persona knows what Sales discussed.

用户先与销售角色对话,之后与客服角色对话:
json
// 销售对话
{
  "persona_id": "p_sales",
  "memory_stores": ["user_alice"]
}

// 客服对话(之后)
{
  "persona_id": "p_support",
  "memory_stores": ["user_alice"]
}
客服角色会知晓销售角色与用户之前的对话内容。

Combining Knowledge + Memories

结合知识库与记忆功能

Full-featured support agent:
bash
undefined
功能完整的客服角色:
bash
undefined

Create persona with knowledge base

创建带知识库的角色

curl -X POST https://tavusapi.com/v2/personas
-H "Content-Type: application/json"
-H "x-api-key: YOUR_API_KEY"
-d '{ "persona_name": "Premium Support", "pipeline_mode": "full", "system_prompt": "You are a premium support agent. Reference the knowledge base for product info. Remember user preferences and past issues.", "document_tags": ["support", "product-docs"], "default_replica_id": "rfe12d8b9597" }'

```bash
curl -X POST https://tavusapi.com/v2/personas
-H "Content-Type: application/json"
-H "x-api-key: YOUR_API_KEY"
-d '{ "persona_name": "Premium Support", "pipeline_mode": "full", "system_prompt": "You are a premium support agent. Reference the knowledge base for product info. Remember user preferences and past issues.", "document_tags": ["support", "product-docs"], "default_replica_id": "rfe12d8b9597" }'

```bash

Start conversation with user memory

启动带用户记忆的对话

curl -X POST https://tavusapi.com/v2/conversations
-H "Content-Type: application/json"
-H "x-api-key: YOUR_API_KEY"
-d '{ "persona_id": "p_premium_support", "memory_stores": ["user_12345_support"], "document_ids": ["d_urgent_issue_docs"] }'

Now the persona can:
- Look up product info from documents
- Remember this user's past issues
- Build on previous conversations
curl -X POST https://tavusapi.com/v2/conversations
-H "Content-Type: application/json"
-H "x-api-key: YOUR_API_KEY"
-d '{ "persona_id": "p_premium_support", "memory_stores": ["user_12345_support"], "document_ids": ["d_urgent_issue_docs"] }'

现在该角色能够:
- 从文档中查找产品信息
- 记住该用户的过往问题
- 基于之前的对话内容继续交流