Qdrant base
QdrantVectorType = tuple[str, list[float]] | qdrant_models.NamedSparseVector
module-attribute
logger = logging.getLogger(__name__)
module-attribute
IncompatibleIndexParamsError
Bases: BackendError
Raised when the index parameters are incompatible with the index type.
QdrantAdapter
My implementation of a qdrant client tied to a specific collection.
Everything here should be general to any collection in qdrant.
collection_name
property
writable
dense_code_embedder = dense_code_embedder
instance-attribute
dense_embedder = dense_embedder
instance-attribute
qdrant_client = qdrant_client
instance-attribute
sparse_embedder
property
__init__(qdrant_client, dense_embedder=default_dense_embedder, dense_code_embedder=default_dense_embedder, sparse_embedder=default_sparse_embedder, collection_name=None)
add_index(metadata_key, params)
async
Add an index to the collection metadata.
| PARAMETER | DESCRIPTION |
|---|---|
metadata_key
|
The key to add the index to
TYPE:
|
params
|
The parameters for the index
TYPE:
|
add_items(upsertables, wait=True)
async
Adds qdrant points to the collection.
Points contain the QdrantPayload information (id, content, metadata). Note: The content is either what was embedded, or where to find it.
| PARAMETER | DESCRIPTION |
|---|---|
upsertables
|
List of Upsertables to add to the collection
TYPE:
|
wait
|
Whether to wait for the operation to complete (defaults to True).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
UpdateResult
|
The qdrant result of the operation |
batch_update(update_operations, wait=False)
async
delete_index(metadata_key)
async
Delete an index from the collection metadata.
delete_items(points_selector, wait=True)
async
get_collection_info()
async
get_count(count_filter)
async
get_index_infos()
async
scroll(scroll_filter=None, limit=100, latest_point_id=None)
async
Scroll through points in collection.
Note: Use scroll_all to iterate all records.
| PARAMETER | DESCRIPTION |
|---|---|
scroll_filter
|
Additional filter to apply to the scroll
TYPE:
|
limit
|
How many results to return in one go
TYPE:
|
latest_point_id
|
The previous latest point id to start from
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[list[QdrantPayload], PointId | None]
|
Tuple of records and the last point id (last point will be None if no more records) |
scroll_all(scroll_filter=None, num_per_iteration=100, limit=None)
async
Scroll through all points in collection.
| PARAMETER | DESCRIPTION |
|---|---|
scroll_filter
|
Additional filter to apply to the scroll
TYPE:
|
num_per_iteration
|
How many results to return per iteration
TYPE:
|
limit
|
Maximum number of records to return
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
AsyncIterator[list[QdrantPayload]]
|
List of records |
search(query_text, query_vector_name=None, k=5, query_filter=None, score_threshold=None, use_sparse=False, offset=0, group_by=None, group_by_count=None)
async
Search collection for items related to query_text.
| PARAMETER | DESCRIPTION |
|---|---|
query_text
|
Text that will be embedded to produce a query vector
TYPE:
|
query_vector_name
|
Name of the vector to use for the query
TYPE:
|
k
|
Number of results to return
TYPE:
|
query_filter
|
Additional qdrant filter to apply to the search
TYPE:
|
score_threshold
|
Minimum score to return
TYPE:
|
use_sparse
|
Whether to use the sparse or dense embeddings
TYPE:
|
offset
|
Offset for pagination
TYPE:
|
group_by
|
Metadata field to group by
TYPE:
|
group_by_count
|
Number of results to return per group
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[QdrantSearchResult]
|
List of search results |
ensure_metadata_prefix(key)
Ensure the key has the metadata prefix.
lc_to_qdrant_sparse_vectors(sparse_vectors)
Ensure the correct SparseVector type is used for qdrant.
Necessary because langchain_qdrant defines an identical SparseVector class that prevents subclass checks passing within qdrant. Re-validating from the qdrant version ensures that the correct class is used.
make_payload_schema_params(type_, is_tenant=False, is_principal=False, on_disk=False)
Create a PayloadSchemaParams object from the given args.
| PARAMETER | DESCRIPTION |
|---|---|
type_
|
The type of the index (e.g., qdrant_models.PayloadSchemaType.KEYWORD)
TYPE:
|
is_tenant
|
Whether to use as a tenant index (e.g., user_id is generally a good tenant index)
TYPE:
|
is_principal
|
Whether to use as a primary index (e.g., timestamp is good for time series)
TYPE:
|
on_disk
|
Whether to store the index on disk (otherwise in-memory)
TYPE:
|
Checks if the additional args are compatible with the type.
strip_metadata_prefix(key)
Strip the metadata prefix from the key.