# 將新文本文件添加到向量儲存

{% openapi src="<https://2492455604-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTVKmtXKPeA8gAZJsuGLA%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media&token=3b4a9db2-4dd7-440f-b670-9555703d351d>" path="/vector-stores/{vector-store-id}/documents/create" method="post" %}
[rememberizer\_openapi.yml](https://2492455604-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTVKmtXKPeA8gAZJsuGLA%2Fuploads%2Fgit-blob-77b6137eeb641262ec8e531c78123c02b825b865%2Frememberizer_openapi.yml?alt=media\&token=3b4a9db2-4dd7-440f-b670-9555703d351d)
{% 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 | 字串 | **必填。** 文件的名稱。   |
| text | 字串 | **必填。** 文件的文本內容。 |

## 回應格式

```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 | 內部伺服器錯誤             |

此端點允許您直接將文本內容添加到您的向量儲存庫中。這對於存儲可能不存在於文件格式中的信息特別有用，例如產品描述、知識庫文章或自定義內容。文本將自動處理為向量嵌入，使其可以通過語義相似性進行搜索。
