Qdrant Python Client Documentation¶
Client library for the Qdrant vector search engine.
Library contains type definitions for all Qdrant API and allows to make both Sync and Async requests.
Pydantic
is used for describing request models and httpx
for handling http queries.
Client allows calls for all Qdrant API methods directly. It also provides some additional helper methods for frequently required operations, e.g. initial collection uploading.
Installation¶
pip install qdrant-client
Examples¶
Instance a client
from qdrant_client import QdrantClient
client = QdrantClient(host="localhost", port=6333)
Create a new collection
from qdrant_client.models import VectorParams, Distance
if not client.collection_exists("my_collection"):
client.create_collection(
collection_name="my_collection",
vectors_config=VectorParams(size=100, distance=Distance.COSINE),
)
Insert vectors into a collection
import numpy as np
from qdrant_client.models import PointStruct
vectors = np.random.rand(100, 100)
client.upsert(
collection_name="my_collection",
points=[
PointStruct(
id=idx,
vector=vector.tolist(),
payload={"color": "red", "rand_number": idx % 10}
)
for idx, vector in enumerate(vectors)
]
)
Search for similar vectors
query_vector = np.random.rand(100)
hits = client.search(
collection_name="my_collection",
query_vector=query_vector,
limit=5 # Return 5 closest points
)
Search for similar vectors with filtering condition
from qdrant_client.models import Filter, FieldCondition, Range
hits = client.search(
collection_name="my_collection",
query_vector=query_vector,
query_filter=Filter(
must=[ # These conditions are required for search results
FieldCondition(
key='rand_number', # Condition based on values of `rand_number` field.
range=Range(
gte=3 # Select only those results where `rand_number` >= 3
)
)
]
),
limit=5 # Return 5 closest points
)
Async Client¶
Starting from version 1.6.1, all python client methods are available in async version.
from qdrant_client import AsyncQdrantClient, models
import numpy as np
import asyncio
async def main():
# Your async code using QdrantClient might be put here
client = AsyncQdrantClient(url="http://localhost:6333")
if not await client.collection_exists("my_collection"):
await client.create_collection(
collection_name="my_collection",
vectors_config=models.VectorParams(size=10, distance=models.Distance.COSINE),
)
await client.upsert(
collection_name="my_collection",
points=[
models.PointStruct(
id=i,
vector=np.random.rand(10).tolist(),
)
for i in range(100)
],
)
res = await client.search(
collection_name="my_collection",
query_vector=np.random.rand(10).tolist(), # type: ignore
limit=10,
)
print(res)
asyncio.run(main())
Both, gRPC and REST API are supported in async mode.
Highlighted Classes¶
Indices and tables¶
- Models
AbortReshardingOperation
AbortShardTransfer
AbortTransferOperation
AliasDescription
AppBuildTelemetry
AppFeaturesTelemetry
Batch
BinaryQuantization
BinaryQuantizationConfig
BoolIndexParams
BoolIndexType
ChangeAliasesOperation
ClearPayloadOperation
ClusterConfigTelemetry
ClusterStatusOneOf
ClusterStatusOneOf1
ClusterStatusTelemetry
ClusterTelemetry
CollectionClusterInfo
CollectionConfig
CollectionConfigInternal
CollectionDescription
CollectionExistence
CollectionInfo
CollectionParams
CollectionParamsDiff
CollectionStatus
CollectionTelemetry
CollectionsAggregatedTelemetry
CollectionsAliasesResponse
CollectionsResponse
CollectionsTelemetry
CompressionRatio
ConsensusConfigTelemetry
ConsensusThreadStatusOneOf
ConsensusThreadStatusOneOf1
ConsensusThreadStatusOneOf2
ContextExamplePair
ContextPair
ContextQuery
CountRequest
CountResult
CpuEndian
CreateAlias
CreateAliasOperation
CreateCollection
CreateFieldIndex
CreateShardingKey
CreateShardingKeyOperation
Datatype
DatetimeIndexParams
DatetimeIndexType
DatetimeRange
DeleteAlias
DeleteAliasOperation
DeleteOperation
DeletePayload
DeletePayloadOperation
DeleteVectors
DeleteVectorsOperation
Direction
Disabled
DiscoverInput
DiscoverQuery
DiscoverRequest
DiscoverRequestBatch
Distance
Document
DropReplicaOperation
DropShardingKey
DropShardingKeyOperation
ErrorResponse
ErrorResponseStatus
FacetRequest
FacetResponse
FacetValueHit
FieldCondition
Filter
FilterSelector
FloatIndexParams
FloatIndexType
Fusion
FusionQuery
GeoBoundingBox
GeoIndexParams
GeoIndexType
GeoLineString
GeoPoint
GeoPolygon
GeoRadius
GpuDeviceTelemetry
GroupsResult
GrpcTelemetry
HardwareTelemetry
HardwareUsage
HasIdCondition
HasVectorCondition
HnswConfig
HnswConfigDiff
Image
IndexesOneOf
IndexesOneOf1
InferenceObject
InitFrom
InlineResponse200
InlineResponse2001
InlineResponse20010
InlineResponse20011
InlineResponse20012
InlineResponse20013
InlineResponse20014
InlineResponse20015
InlineResponse20016
InlineResponse20017
InlineResponse20018
InlineResponse20019
InlineResponse2002
InlineResponse20020
InlineResponse20021
InlineResponse20022
InlineResponse20023
InlineResponse20024
InlineResponse20025
InlineResponse2003
InlineResponse2004
InlineResponse2005
InlineResponse2006
InlineResponse2007
InlineResponse2008
InlineResponse2009
InlineResponse202
IntegerIndexParams
IntegerIndexType
IsEmptyCondition
IsNullCondition
KeywordIndexParams
KeywordIndexType
LocalShardInfo
LocalShardTelemetry
LocksOption
LookupLocation
MatchAny
MatchExcept
MatchText
MatchValue
MaxOptimizationThreadsSetting
MemoryTelemetry
MessageSendErrors
MinShould
Modifier
MoveShard
MoveShardOperation
MultiVectorComparator
MultiVectorConfig
NamedSparseVector
NamedVector
NearestQuery
Nested
NestedCondition
OperationDurationStatistics
OptimizerTelemetry
OptimizersConfig
OptimizersConfigDiff
OptimizersStatusOneOf
OptimizersStatusOneOf1
OrderBy
OrderByQuery
OverwritePayloadOperation
P2pConfigTelemetry
PayloadField
PayloadIndexInfo
PayloadIndexTelemetry
PayloadSchemaType
PayloadSelectorExclude
PayloadSelectorInclude
PayloadStorageTypeOneOf
PayloadStorageTypeOneOf1
PayloadStorageTypeOneOf2
PeerInfo
PointGroup
PointIdsList
PointRequest
PointStruct
PointVectors
PointsBatch
PointsList
Prefetch
ProductQuantization
ProductQuantizationConfig
QuantizationSearchParams
QueryGroupsRequest
QueryRequest
QueryRequestBatch
QueryResponse
RaftInfo
Range
ReadConsistencyType
RecommendGroupsRequest
RecommendInput
RecommendQuery
RecommendRequest
RecommendRequestBatch
RecommendStrategy
Record
RemoteShardInfo
RemoteShardTelemetry
RenameAlias
RenameAliasOperation
Replica
ReplicaSetTelemetry
ReplicaState
ReplicateShard
ReplicateShardOperation
RequestsTelemetry
ReshardingDirectionOneOf
ReshardingDirectionOneOf1
ReshardingInfo
RestartTransfer
RestartTransferOperation
RunningEnvironmentTelemetry
Sample
SampleQuery
ScalarQuantization
ScalarQuantizationConfig
ScalarType
ScoredPoint
ScrollRequest
ScrollResult
SearchGroupsRequest
SearchMatrixOffsetsResponse
SearchMatrixPair
SearchMatrixPairsResponse
SearchMatrixRequest
SearchParams
SearchRequest
SearchRequestBatch
SegmentConfig
SegmentInfo
SegmentTelemetry
SegmentType
SetPayload
SetPayloadOperation
ShardCleanStatusFailedTelemetry
ShardCleanStatusProgressTelemetry
ShardCleanStatusTelemetryOneOf
ShardCleanStatusTelemetryOneOf1
ShardCleanStatusTelemetryOneOf2
ShardSnapshotRecover
ShardStatus
ShardTransferInfo
ShardTransferMethodOneOf
ShardTransferMethodOneOf1
ShardTransferMethodOneOf2
ShardTransferMethodOneOf3
ShardingMethod
SnapshotDescription
SnapshotPriority
SnapshotRecover
SparseIndexConfig
SparseIndexParams
SparseIndexTypeOneOf
SparseIndexTypeOneOf1
SparseIndexTypeOneOf2
SparseVector
SparseVectorDataConfig
SparseVectorParams
SparseVectorStorageTypeOneOf
SparseVectorStorageTypeOneOf1
StartResharding
StartReshardingOperation
StateRole
StrictModeConfig
TelemetryData
TextIndexParams
TextIndexType
TokenizerType
TrackerStatusOneOf
TrackerStatusOneOf1
TrackerStatusOneOf2
TrackerTelemetry
UpdateCollection
UpdateOperations
UpdateResult
UpdateStatus
UpdateVectors
UpdateVectorsOperation
UpsertOperation
UuidIndexParams
UuidIndexType
ValuesCount
VectorDataConfig
VectorDataInfo
VectorIndexSearchesTelemetry
VectorParams
VectorParamsDiff
VectorStorageDatatype
VectorStorageTypeOneOf
VectorStorageTypeOneOf1
VectorStorageTypeOneOf2
VectorStorageTypeOneOf3
VersionInfo
WalConfig
WalConfigDiff
WebApiTelemetry
WithLookup
WriteOrdering
- Exceptions
- QdrantClient
- AsyncQdrantClient
- FastEmbed Mixin