Client library for the Qdrant vector search engine
—
Payload field indexing, collection optimization, and performance tuning capabilities.
Create indexes on payload fields for faster filtering.
def create_payload_index(
self,
collection_name: str,
field_name: str,
field_schema: Optional[PayloadFieldSchema] = None,
wait: bool = True,
ordering: Optional[WriteOrdering] = None,
**kwargs
) -> UpdateResult:
"""
Create index on payload field.
Parameters:
- collection_name: Name of the collection
- field_name: Payload field name to index
- field_schema: Index configuration and field type
- wait: Wait for operation to complete
- ordering: Write ordering guarantees
Returns:
UpdateResult: Result of the operation
"""
def delete_payload_index(
self,
collection_name: str,
field_name: str,
wait: bool = True,
ordering: Optional[WriteOrdering] = None,
**kwargs
) -> UpdateResult:
"""
Delete payload field index.
Parameters:
- collection_name: Name of the collection
- field_name: Payload field name
- wait: Wait for operation to complete
- ordering: Write ordering guarantees
Returns:
UpdateResult: Result of the operation
"""
def list_payload_indexes(
self,
collection_name: str,
**kwargs
) -> Dict[str, PayloadIndexInfo]:
"""
List all payload indexes in collection.
Parameters:
- collection_name: Name of the collection
Returns:
Dict[str, PayloadIndexInfo]: Mapping of field names to index info
"""Usage examples:
from qdrant_client import models
# Create keyword index for exact matching
client.create_payload_index(
collection_name="documents",
field_name="category",
field_schema=models.KeywordIndexParams(
type="keyword",
on_disk=False
)
)
# Create integer index for numeric fields
client.create_payload_index(
collection_name="documents",
field_name="timestamp",
field_schema=models.IntegerIndexParams(
type="integer",
range=True,
on_disk=True
)
)
# Create text index for full-text search
client.create_payload_index(
collection_name="documents",
field_name="content",
field_schema=models.TextIndexParams(
type="text",
tokenizer="word",
min_token_len=2,
max_token_len=20,
lowercase=True,
on_disk=True
)
)
# Create geo index for geographic queries
client.create_payload_index(
collection_name="locations",
field_name="coordinates",
field_schema=models.GeoIndexParams(
type="geo",
on_disk=False
)
)Optimize collection storage and search performance.
def optimize_collection(
self,
collection_name: str,
wait: bool = True,
**kwargs
) -> UpdateResult:
"""
Optimize collection by rebuilding indexes and compacting storage.
Parameters:
- collection_name: Name of the collection
- wait: Wait for operation to complete
Returns:
UpdateResult: Result of the operation
"""Manage vector indexes for search performance.
def recreate_index(
self,
collection_name: str,
wait: bool = True,
**kwargs
) -> UpdateResult:
"""
Recreate vector index with current configuration.
Parameters:
- collection_name: Name of the collection
- wait: Wait for operation to complete
Returns:
UpdateResult: Result of the operation
"""For exact string matching and categorical fields.
class KeywordIndexParams(BaseModel):
type: Literal["keyword"] = "keyword"
on_disk: Optional[bool] = None # Store index on diskBest for:
For numeric fields with range queries.
class IntegerIndexParams(BaseModel):
type: Literal["integer"] = "integer"
range: bool = True # Enable range queries
on_disk: Optional[bool] = None # Store index on diskBest for:
For floating-point numeric fields.
class FloatIndexParams(BaseModel):
type: Literal["float"] = "float"
range: bool = True # Enable range queries
on_disk: Optional[bool] = None # Store index on diskBest for:
For boolean fields.
class BoolIndexParams(BaseModel):
type: Literal["bool"] = "bool"
on_disk: Optional[bool] = None # Store index on diskBest for:
For geographic coordinate fields.
class GeoIndexParams(BaseModel):
type: Literal["geo"] = "geo"
on_disk: Optional[bool] = None # Store index on diskBest for:
For full-text search capabilities.
class TextIndexParams(BaseModel):
type: Literal["text"] = "text"
tokenizer: TextIndexTokenizer = "word" # Tokenization method
min_token_len: Optional[int] = None # Minimum token length
max_token_len: Optional[int] = None # Maximum token length
lowercase: Optional[bool] = None # Convert to lowercase
on_disk: Optional[bool] = None # Store index on disk
class TextIndexTokenizer(str, Enum):
WORD = "word" # Word-based tokenization
WHITESPACE = "whitespace" # Whitespace tokenization
PREFIX = "prefix" # Prefix-based tokenizationBest for:
class PayloadIndexInfo(BaseModel):
data_type: PayloadSchemaType
params: Optional[PayloadIndexParams] = None
points: Optional[int] = None # Number of indexed points
class PayloadSchemaType(str, Enum):
KEYWORD = "keyword"
INTEGER = "integer"
FLOAT = "float"
GEO = "geo"
TEXT = "text"
BOOL = "bool"
DATETIME = "datetime"Use keyword indexes when:
Use integer/float indexes when:
Use text indexes when:
Use geo indexes when:
In-memory indexes (on_disk=False):
On-disk indexes (on_disk=True):
on_disk=True for less critical indexes# Example: Strategic indexing for a document collection
collection_name = "documents"
# High-cardinality field used in filters - keyword index
client.create_payload_index(
collection_name=collection_name,
field_name="document_id",
field_schema=models.KeywordIndexParams(type="keyword", on_disk=False)
)
# Numeric field for range queries - integer index
client.create_payload_index(
collection_name=collection_name,
field_name="timestamp",
field_schema=models.IntegerIndexParams(type="integer", range=True, on_disk=True)
)
# Full-text searchable content - text index
client.create_payload_index(
collection_name=collection_name,
field_name="content",
field_schema=models.TextIndexParams(
type="text",
tokenizer="word",
lowercase=True,
on_disk=True # Large text index on disk
)
)
# Boolean flag for filtering - bool index
client.create_payload_index(
collection_name=collection_name,
field_name="published",
field_schema=models.BoolIndexParams(type="bool", on_disk=False)
)# Efficient queries using indexed fields
from qdrant_client import models
# Keyword index query (exact match)
results = client.query_points(
collection_name="documents",
query=query_vector,
query_filter=models.Filter(
must=[
models.FieldCondition(
key="category", # Indexed keyword field
match=models.MatchValue(value="technology")
)
]
)
)
# Range query on indexed numeric field
results = client.query_points(
collection_name="documents",
query=query_vector,
query_filter=models.Filter(
must=[
models.FieldCondition(
key="timestamp", # Indexed integer field
range=models.Range(
gte=1640995200, # Jan 1, 2022
lte=1672531199 # Dec 31, 2022
)
)
]
)
)
# Full-text search on indexed text field
results = client.query_points(
collection_name="documents",
query=query_vector,
query_filter=models.Filter(
must=[
models.FieldCondition(
key="content", # Indexed text field
match=models.MatchText(text="machine learning")
)
]
)
)Install with Tessl CLI
npx tessl i tessl/pypi-qdrant-client