跳至主要內容

/vector_stores/{vector_store_id}/files

向量儲存檔案代表位於向量儲存內的個別檔案。

功能支援
記錄✅(完整請求/回應記錄)
支援的提供者openai

支援的操作​

操作說明OpenAI Python ClientLiteLLM Proxy
建立向量儲存檔案將檔案附加到向量儲存,可選擇覆寫分塊設定✅✅
列出向量儲存檔案可分頁列出並可篩選✅✅
取得向量儲存檔案擷取單一檔案的中繼資料✅✅
刪除向量儲存檔案從儲存中移除檔案(檔案物件仍會保留)✅✅
取得向量儲存檔案內容串流處理後的分塊❌✅
更新向量儲存檔案屬性修改自訂屬性❌✅
備註

向量儲存支援目前僅適用於 OpenAI 向量儲存與 OpenAI 上傳的檔案 ID。

建立向量儲存檔案​

POST http://localhost:4000/v1/vector_stores/{vector_store_id}/files
from openai import OpenAI

client = OpenAI(
base_url="http://localhost:4000", # LiteLLM proxy or OpenAI base
api_key="sk-<your-litellm-api-key>"
)

vector_store_file = client.vector_stores.files.create(
vector_store_id="vs_69172088a18c8191ab3e2621aa87d1ee",
file_id="file-NDbEDJTfqVh7S4Ugi3CGYw",
chunking_strategy={
"type": "static",
"static": {
"max_chunk_size_tokens": 800,
"chunk_overlap_tokens": 400,
},
},
)

print(vector_store_file)

列出向量儲存檔案​

GET http://localhost:4000/v1/vector_stores/&#123;vector_store_id&#125;/files

參數:

  • vector_store_id(path,必填)
  • after / before(query,選填)– 分頁游標
  • filter(query,選填)– in_progress、completed、failed、cancelled
  • limit(query,選填,預設 20,範圍 1-100)
  • order(query,選填,預設 desc)
vector_store_files = client.vector_stores.files.list(
vector_store_id="vs_abc123"
)
print(vector_store_files)

取得向量儲存檔案​

GET http://localhost:4000/v1/vector_stores/&#123;vector_store_id&#125;/files/&#123;file_id&#125;
vector_store_file = client.vector_stores.files.retrieve(
vector_store_id="vs_abc123",
file_id="file-abc123"
)
print(vector_store_file)

刪除向量儲存檔案​

DELETE http://localhost:4000/v1/vector_stores/&#123;vector_store_id&#125;/files/&#123;file_id&#125;
deleted_vector_store_file = client.vector_stores.files.delete(
vector_store_id="vs_abc123",
file_id="file-abc123"
)
print(deleted_vector_store_file)

僅限 Proxy 的端點​

當您需要原始內容分塊或屬性更新時,請直接呼叫 LiteLLM Proxy。

取得檔案內容​

curl -X GET "http://localhost:4000/v1/vector_stores/\{vector_store_id\}/files/\{file_id\}/content" \
-H "Authorization: Bearer $LITELLM_API_KEY"

更新檔案屬性​

curl -X POST "http://localhost:4000/v1/vector_stores/\{vector_store_id\}/files/\{file_id\}" \
-H "Authorization: Bearer $LITELLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"attributes": {
"category": "support-faq",
"language": "en"
}
}'