| Property |
Value
|
| sources |
litellm/vector_stores/main.py
|
| domains |
Vector Stores, Search, Retrieval, OpenAI
|
| last_updated |
2026-02-15 16:00 GMT
|
Overview
The Vector Stores API module provides functions for creating vector stores and searching them for relevant content chunks, with built-in mock response support and integration with the vector store registry for credential management.
Description
This module implements two primary operations through sync/async function pairs: create/acreate for creating vector stores and search/asearch for searching vector stores. Both use the @client decorator and default to "openai" as the provider. The create function accepts configuration for file IDs, expiration policies, chunking strategies, and metadata, delegating to BaseLLMHTTPHandler.vector_store_create_handler(). The search function accepts queries (string or list), filters, max results, ranking options, and rewrite query flags, delegating to BaseLLMHTTPHandler.vector_store_search_handler(). The search function integrates with litellm.vector_store_registry for automatic credential injection. Both functions support provider resolution via /-prefixed provider strings (e.g., openai/). The module provides mock_vector_store_search_response() and mock_vector_store_create_response() for testing.
Usage
Import this module when you need to create a new vector store or search an existing one for relevant document chunks. It is the primary interface for vector store lifecycle management and semantic search through LiteLLM.
Code Reference
Source Location
| Property |
Value
|
| Repository |
github.com/BerriAI/litellm
|
| File |
litellm/vector_stores/main.py
|
| Lines |
482
|
| Module |
litellm.vector_stores.main
|
Signature
@client
def create(
name: Optional[str] = None,
file_ids: Optional[List[str]] = None,
expires_after: Optional[Dict] = None,
chunking_strategy: Optional[Dict] = None,
metadata: Optional[Dict[str, str]] = None,
extra_headers: Optional[Dict[str, Any]] = None,
extra_query: Optional[Dict[str, Any]] = None,
extra_body: Optional[Dict[str, Any]] = None,
timeout: Optional[Union[float, httpx.Timeout]] = None,
custom_llm_provider: Optional[str] = None,
**kwargs,
) -> Union[VectorStoreCreateResponse, Coroutine]
@client
def search(
vector_store_id: str,
query: Union[str, List[str]],
filters: Optional[Dict] = None,
max_num_results: Optional[int] = None,
ranking_options: Optional[Dict] = None,
rewrite_query: Optional[bool] = None,
extra_headers: Optional[Dict[str, Any]] = None,
extra_query: Optional[Dict[str, Any]] = None,
extra_body: Optional[Dict[str, Any]] = None,
timeout: Optional[Union[float, httpx.Timeout]] = None,
custom_llm_provider: Optional[str] = None,
**kwargs,
) -> Union[VectorStoreSearchResponse, Coroutine]
Import
from litellm.vector_stores.main import (
create, acreate,
search, asearch,
mock_vector_store_search_response,
mock_vector_store_create_response,
)
I/O Contract
Inputs
| Parameter |
Type |
Required |
Description
|
name |
Optional[str] |
No |
Name of the vector store to create
|
file_ids |
Optional[List[str]] |
No |
File IDs to include in the vector store
|
expires_after |
Optional[Dict] |
No |
Expiration policy for the vector store
|
chunking_strategy |
Optional[Dict] |
No |
Chunking strategy for files in the store
|
metadata |
Optional[Dict[str, str]] |
No |
Up to 16 key-value metadata pairs
|
vector_store_id |
str |
For search |
The ID of the vector store to search
|
query |
Union[str, List[str]] |
For search |
The search query or array of queries
|
filters |
Optional[Dict] |
No |
Attribute-based filter for search
|
max_num_results |
Optional[int] |
No |
Maximum results to return (1-50, default 10)
|
ranking_options |
Optional[Dict] |
No |
Ranking configuration for search results
|
rewrite_query |
Optional[bool] |
No |
Whether to rewrite the query for vector search
|
Outputs
| Function |
Return Type |
Description
|
create |
VectorStoreCreateResponse |
Created store with id, status, file_counts, metadata
|
search |
VectorStoreSearchResponse |
Search results with scores, content, and query info
|
Usage Examples
import litellm
# Create a vector store
vs = litellm.vector_stores.create(
name="My Knowledge Base",
file_ids=["file_abc123", "file_def456"],
chunking_strategy={"type": "auto"},
)
print(f"Vector Store ID: {vs.id}, Status: {vs.status}")
import litellm
# Search a vector store
results = litellm.vector_stores.search(
vector_store_id="vs_abc123",
query="What is machine learning?",
max_num_results=5,
)
for result in results.data:
print(f"Score: {result.score}")
for content in result.content:
print(f" {content.text[:100]}...")
Related Pages