跳至主要內容

/vector_stores/search - 搜尋向量儲存

依據查詢與檔案屬性篩選條件搜尋向量儲存中相關的區塊。這對檢索增強生成(RAG)使用案例很有幫助。

概覽​

功能支援備註
成本追蹤✅依每次搜尋作業追蹤
記錄✅可跨所有整合使用
終端使用者追蹤✅
支援 LLM 提供者OpenAI, Azure OpenAI, Bedrock, Vertex RAG Engine, Azure AI, Milvus, Valkey, Gemini跨提供者完整支援 vector stores API

如需透過 HTTP 進行 retrieve、list、update 與 delete(包含 custom_llm_provider / model 路由),請參閱建立向量儲存。

用法​

LiteLLM Python SDK​

非串流範例​

Search Vector Store - Basic
import litellm

response = await litellm.vector_stores.asearch(
vector_store_id="vs_abc123",
query="What is the capital of France?"
)
print(response)

同步範例​

Search Vector Store - Sync
import litellm

response = litellm.vector_stores.search(
vector_store_id="vs_abc123",
query="What is the capital of France?"
)
print(response)

LiteLLM Proxy Server​

  1. 設定 config.yaml
model_list:
- model_name: gpt-5.6-terra
litellm_params:
model: openai/gpt-5.6-terra
api_key: os.environ/OPENAI_API_KEY

general_settings:
# Vector store settings can be added here if needed
  1. 啟動 proxy
litellm --config /path/to/config.yaml
  1. 使用 OpenAI SDK 測試它!
OpenAI SDK via LiteLLM Proxy
from openai import OpenAI

# Point OpenAI SDK to LiteLLM proxy
client = OpenAI(
base_url="http://0.0.0.0:4000",
api_key="sk-<your-litellm-api-key>", # Your LiteLLM API key
)

search_results = client.beta.vector_stores.search(
vector_store_id="vs_abc123",
query="What is the capital of France?",
max_num_results=5
)
print(search_results)

設定向量儲存​

若要搜尋已存在於某個提供者上的儲存區,請先透過 config.yaml、POST /vector_store/new,或 Admin UI 將其註冊至 LiteLLM;請參閱 受管理的 Vector Stores。關於提供者特定的設定,請參閱 Vector Store 設定指南:

  • 提供者特定設定(Bedrock、OpenAI、Azure、Vertex AI、PG Vector)
  • Python SDK 與 Proxy 設定範例
  • 驗證與憑證管理

在 Chat Completions 中使用向量儲存​

在 chat completion 請求中傳入 vector_store_ids,即可自動擷取相關脈絡。請參閱在 Chat Completions 中使用向量儲存以了解實作細節。

LiteLLM Enterprise
為正式環境打造的 SSO/SAML、稽核記錄、支出追蹤、多團隊管理與防護欄。
深入瞭解 →