# 向向量存储添加新文本文档

{% openapi src="<https://1371168417-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4gvX7KIUy0DhcQETj8Ux%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media&token=cce1ab0d-330f-4bed-b7da-5635aaf25472>" path="/vector-stores/{vector-store-id}/documents/create" method="post" %}
[rememberizer\_openapi.yml](https://1371168417-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4gvX7KIUy0DhcQETj8Ux%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media\&token=cce1ab0d-330f-4bed-b7da-5635aaf25472)
{% endopenapi %}

## 示例请求

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST \
  https://api.rememberizer.ai/api/v1/vector-stores/vs_abc123/documents/create \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "产品概述",
    "text": "我们的产品是一个创新的解决方案，用于管理向量嵌入。它与您现有的系统无缝集成，并提供强大的语义搜索功能。"
  }'
```

{% hint style="info" %}
将 `YOUR_API_KEY` 替换为您的实际向量存储 API 密钥，将 `vs_abc123` 替换为您的向量存储 ID。
{% endhint %}
{% endtab %}

{% tab title="JavaScript" %}

```javascript
const addTextDocument = async (vectorStoreId, name, text) => {
  const response = await fetch(`https://api.rememberizer.ai/api/v1/vector-stores/${vectorStoreId}/documents/create`, {
    method: 'POST',
    headers: {
      'x-api-key': 'YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      name: name,
      text: text
    })
  });
  
  const data = await response.json();
  console.log(data);
};

addTextDocument(
  'vs_abc123',
  '产品概述',
  '我们的产品是一个创新的解决方案，用于管理向量嵌入。它与您现有的系统无缝集成，并提供强大的语义搜索功能。'
);
```

{% hint style="info" %}
将 `YOUR_API_KEY` 替换为您的实际向量存储 API 密钥，将 `vs_abc123` 替换为您的向量存储 ID。
{% endhint %}
{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

def add_text_document(vector_store_id, name, text):
    headers = {
        "x-api-key": "YOUR_API_KEY",
        "Content-Type": "application/json"
    }
    
    payload = {
        "name": name,
        "text": text
    }
    
    response = requests.post(
        f"https://api.rememberizer.ai/api/v1/vector-stores/{vector_store_id}/documents/create",
        headers=headers,
        data=json.dumps(payload)
    )
    
    data = response.json()
    print(data)

add_text_document(
    'vs_abc123',
    '产品概述',
    '我们的产品是一个创新的解决方案，用于管理向量嵌入。它与您现有的系统无缝集成，并提供强大的语义搜索功能。'
)
```

{% hint style="info" %}
将 `YOUR_API_KEY` 替换为您的实际向量存储 API 密钥，将 `vs_abc123` 替换为您的向量存储 ID。
{% endhint %}
{% endtab %}
{% endtabs %}

## 路径参数

| 参数              | 类型  | 描述                      |
| --------------- | --- | ----------------------- |
| vector-store-id | 字符串 | **必需。** 要添加文档的向量存储的 ID。 |

## 请求体

```json
{
  "name": "产品概述",
  "text": "我们的产品是一个用于管理向量嵌入的创新解决方案。它与您现有的系统无缝集成，并提供强大的语义搜索功能。"
}
```

| 参数   | 类型     | 描述               |
| ---- | ------ | ---------------- |
| name | string | **必填。** 文档的名称。   |
| text | string | **必填。** 文档的文本内容。 |

## 响应格式

```json
{
  "id": 1234,
  "name": "产品概述",
  "type": "text/plain",
  "vector_store": "vs_abc123",
  "size": 173,
  "status": "处理中",
  "processing_status": "排队中",
  "indexed_on": null,
  "status_error_message": null,
  "created": "2023-06-15T10:15:00Z",
  "modified": "2023-06-15T10:15:00Z"
}
```

## 认证

此端点需要使用 `x-api-key` 头中的 API 密钥进行认证。

## 错误响应

| 状态码 | 描述                 |
| --- | ------------------ |
| 400 | 错误请求 - 缺少必需字段或格式无效 |
| 401 | 未授权 - API 密钥无效或缺失  |
| 404 | 未找到 - 找不到向量存储      |
| 500 | 内部服务器错误            |

此端点允许您直接将文本内容添加到您的向量存储中。它特别适用于存储可能不存在于文件格式中的信息，例如产品描述、知识库文章或自定义内容。文本将自动处理为向量嵌入，使其可以通过语义相似性进行搜索。
