/vector_stores/search - Search Vector Store
Search a vector store for relevant chunks based on a query and file attributes filter. This is useful for retrieval-augmented generation (RAG) use cases.
Overviewโ
| Feature | Supported | Notes |
|---|---|---|
| Cost Tracking | โ | Tracked per search operation |
| Logging | โ | Works across all integrations |
| End-user Tracking | โ | |
| Support LLM Providers | OpenAI, Azure OpenAI, Bedrock, Vertex RAG Engine, Azure AI, Milvus, Valkey, Gemini | Full vector stores API support across providers |
For retrieve, list, update, and delete over HTTP (including custom_llm_provider / model routing), see Create vector store.
Usageโ
LiteLLM Python SDKโ
- Basic Usage
- Advanced Configuration
- Multiple Queries
- OpenAI Provider
- Azure AI Provider
- Milvus Provider
- MongoDB Provider (BETA)
- Valkey Provider
- Gemini Provider
Non-streaming exampleโ
import litellm
response = await litellm.vector_stores.asearch(
vector_store_id="vs_abc123",
query="What is the capital of France?"
)
print(response)
Synchronous exampleโ
import litellm
response = litellm.vector_stores.search(
vector_store_id="vs_abc123",
query="What is the capital of France?"
)
print(response)
With filters and ranking optionsโ
import litellm
response = await litellm.vector_stores.asearch(
vector_store_id="vs_abc123",
query="What is the capital of France?",
filters={
"file_ids": ["file-abc123", "file-def456"]
},
max_num_results=5,
ranking_options={
"score_threshold": 0.7
},
rewrite_query=True
)
print(response)
Searching with multiple queriesโ
import litellm
response = await litellm.vector_stores.asearch(
vector_store_id="vs_abc123",
query=[
"What is the capital of France?",
"What is the population of Paris?"
],
max_num_results=10
)
print(response)
Using OpenAI provider explicitlyโ
import litellm
import os
# Set API key
os.environ["OPENAI_API_KEY"] = "your-openai-api-key"
response = await litellm.vector_stores.asearch(
vector_store_id="vs_abc123",
query="What is the capital of France?",
custom_llm_provider="openai"
)
print(response)
Using Azure AI Searchโ
import litellm
import os
# Set credentials
os.environ["AZURE_SEARCH_API_KEY"] = "your-search-api-key"
response = await litellm.vector_stores.asearch(
vector_store_id="my-vector-index",
query="What is the capital of France?",
custom_llm_provider="azure_ai",
azure_search_service_name="your-search-service",
litellm_embedding_model="azure/text-embedding-3-large",
litellm_embedding_config={
"api_base": "your-embedding-endpoint",
"api_key": "your-embedding-api-key",
},
api_key=os.getenv("AZURE_SEARCH_API_KEY"),
)
print(response)
Using Milvusโ
import litellm
import os
# Set credentials
os.environ["MILVUS_API_KEY"] = "your-milvus-api-key"
os.environ["MILVUS_API_BASE"] = "https://your-milvus-instance.milvus.io"
response = await litellm.vector_stores.asearch(
vector_store_id="my-collection-name",
query="What is the capital of France?",
custom_llm_provider="milvus",
litellm_embedding_model="azure/text-embedding-3-large",
litellm_embedding_config={
"api_base": "your-embedding-endpoint",
"api_key": "your-embedding-api-key",
},
milvus_text_field="book_intro",
api_key=os.getenv("MILVUS_API_KEY"),
)
print(response)
Using MongoDB (BETA)โ
Search an existing MongoDB Vector Search index on Atlas or a self-managed deployment. Install litellm[mongodb], then set MONGODB_CONNECTION_STRING and your embedding provider's credentials. Replace the placeholders with your index, collection fields, and the model used to embed your documents.
import os
import litellm
response = await litellm.vector_stores.asearch(
vector_store_id="<index-name>", # Exact MongoDB Vector Search index name
query="<question-about-your-documents>",
custom_llm_provider="mongodb",
mongodb_connection_string=os.environ["MONGODB_CONNECTION_STRING"],
mongodb_database="<database-name>",
mongodb_collection="<collection-name>",
mongodb_text_field="<text-field>",
mongodb_embedding_field="<vector-field>",
litellm_embedding_model="<provider>/<embedding-model>",
max_num_results=3,
)
print(response)
The embedding model must match the one used for the stored vectors. This BETA integration supports search only; index creation, ingestion, filters, ranking options, and query rewriting are not supported.
Using Valkeyโ
import litellm
response = await litellm.vector_stores.asearch(
vector_store_id="my-search-index", # name of the FT index in Valkey
query="What is the capital of France?",
custom_llm_provider="valkey",
valkey_host="my-valkey.example.com",
valkey_port=6379,
litellm_embedding_model="openai/text-embedding-3-small",
max_num_results=3,
)
print(response)
Using Gemini File Searchโ
import litellm
import os
# Set credentials
os.environ["GEMINI_API_KEY"] = "your-gemini-api-key"
response = await litellm.vector_stores.asearch(
vector_store_id="fileSearchStores/your-store-id",
query="What is the capital of France?",
custom_llm_provider="gemini",
max_num_results=5
)
print(response)
With Metadata Filter:
response = await litellm.vector_stores.asearch(
vector_store_id="fileSearchStores/your-store-id",
query="What is LiteLLM?",
custom_llm_provider="gemini",
filters={"author": "John Doe", "category": "documentation"},
max_num_results=5
)
print(response)
LiteLLM Proxy Serverโ
- Setup & Usage
- curl
- Setup 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
- Start proxy
litellm --config /path/to/config.yaml
- Test it with OpenAI SDK!
from openai import OpenAI
# Point OpenAI SDK to LiteLLM proxy
client = OpenAI(
base_url="http://0.0.0.0:4000",
api_key="sk-1234", # 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)
curl -L -X POST 'http://0.0.0.0:4000/v1/vector_stores/vs_abc123/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer sk-1234' \
-d '{
"query": "What is the capital of France?",
"filters": {
"file_ids": ["file-abc123", "file-def456"]
},
"max_num_results": 5,
"ranking_options": {
"score_threshold": 0.7
},
"rewrite_query": true
}'
Setting Up Vector Storesโ
To search a store that already exists on a provider, register it with LiteLLM first via config.yaml, POST /vector_store/new, or the Admin UI; see Managed Vector Stores. For provider-specific configuration, see the Vector Store Configuration Guide:
- Provider-specific configuration (Bedrock, OpenAI, Azure, Vertex AI, PG Vector)
- Python SDK and Proxy setup examples
- Authentication and credential management
Using Vector Stores with Chat Completionsโ
Pass vector_store_ids in chat completion requests to automatically retrieve relevant context. See Using Vector Stores with Chat Completions for implementation details.