langchain_community.vectorstores.qdrant.Qdrant

class langchain_community.vectorstores.qdrant.Qdrant(client: Any, collection_name: str, embeddings: Optional[Embeddings] = None, content_payload_key: str = 'page_content', metadata_payload_key: str = 'metadata', distance_strategy: str = 'COSINE', vector_name: Optional[str] = None, async_client: Optional[Any] = None, embedding_function: Optional[Callable] = None)[source]

[Deprecated] Qdrant vector store.

To use you should have the qdrant-client package installed.

Example

from qdrant_client import QdrantClient
from langchain_community.vectorstores import Qdrant

client = QdrantClient()
collection_name = "MyCollection"
qdrant = Qdrant(client, collection_name, embedding_function)

Notes

Deprecated since version 0.0.37.

Initialize with necessary components.

Attributes

CONTENT_KEY

METADATA_KEY

VECTOR_NAME

embeddings

Access the query embedding object if available.

Methods

__init__(client, collection_name[, ...])

Initialize with necessary components.

aadd_documents(documents, **kwargs)

Run more documents through the embeddings and add to the vectorstore.

aadd_texts(texts[, metadatas, ids, batch_size])

Run more texts through the embeddings and add to the vectorstore.

aconstruct_instance(texts, embedding[, ...])

add_documents(documents, **kwargs)

Run more documents through the embeddings and add to the vectorstore.

add_texts(texts[, metadatas, ids, batch_size])

Run more texts through the embeddings and add to the vectorstore.

adelete([ids])

Delete by vector ID or other criteria.

afrom_documents(documents, embedding, **kwargs)

Return VectorStore initialized from documents and embeddings.

afrom_texts(texts, embedding[, metadatas, ...])

Construct Qdrant wrapper from a list of texts.

amax_marginal_relevance_search(query[, k, ...])

Return docs selected using the maximal marginal relevance.

amax_marginal_relevance_search_by_vector(...)

Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. :param query: Text to look up documents similar to. :param k: Number of Documents to return. Defaults to 4. :param fetch_k: Number of Documents to fetch to pass to MMR algorithm. Defaults to 20. :param lambda_mult: Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. :param filter: Filter by metadata. Defaults to None. :param search_params: Additional search params :param score_threshold: Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned. :param consistency: Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all queried replicas - 'majority' - query all replicas, but return values present in the majority of replicas - 'quorum' - query the majority of replicas, return values present in all of them - 'all' - query all replicas, and return values present in all replicas :param **kwargs: Any other named arguments to pass through to AsyncQdrantClient.Search().

amax_marginal_relevance_search_with_score_by_vector(...)

Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. :param query: Text to look up documents similar to. :param k: Number of Documents to return. Defaults to 4. :param fetch_k: Number of Documents to fetch to pass to MMR algorithm. Defaults to 20. :param lambda_mult: Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5.

as_retriever(**kwargs)

Return VectorStoreRetriever initialized from this VectorStore.

asearch(query, search_type, **kwargs)

Return docs most similar to query using specified search type.

asimilarity_search(query[, k, filter])

Return docs most similar to query.

asimilarity_search_by_vector(embedding[, k, ...])

Return docs most similar to embedding vector.

asimilarity_search_with_relevance_scores(query)

Return docs and relevance scores in the range [0, 1].

asimilarity_search_with_score(query[, k, ...])

Return docs most similar to query.

asimilarity_search_with_score_by_vector(...)

Return docs most similar to embedding vector.

construct_instance(texts, embedding[, ...])

delete([ids])

Delete by vector ID or other criteria.

from_documents(documents, embedding, **kwargs)

Return VectorStore initialized from documents and embeddings.

from_existing_collection(embedding, path, ...)

Get instance of an existing Qdrant collection.

from_texts(texts, embedding[, metadatas, ...])

Construct Qdrant wrapper from a list of texts.

max_marginal_relevance_search(query[, k, ...])

Return docs selected using the maximal marginal relevance.

max_marginal_relevance_search_by_vector(...)

Return docs selected using the maximal marginal relevance.

max_marginal_relevance_search_with_score_by_vector(...)

Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. :param query: Text to look up documents similar to. :param k: Number of Documents to return. Defaults to 4. :param fetch_k: Number of Documents to fetch to pass to MMR algorithm. Defaults to 20. :param lambda_mult: Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. :param filter: Filter by metadata. Defaults to None. :param search_params: Additional search params :param score_threshold: Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned. :param consistency: Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all queried replicas - 'majority' - query all replicas, but return values present in the majority of replicas - 'quorum' - query the majority of replicas, return values present in all of them - 'all' - query all replicas, and return values present in all replicas :param **kwargs: Any other named arguments to pass through to QdrantClient.search().

search(query, search_type, **kwargs)

Return docs most similar to query using specified search type.

similarity_search(query[, k, filter, ...])

Return docs most similar to query.

similarity_search_by_vector(embedding[, k, ...])

Return docs most similar to embedding vector.

similarity_search_with_relevance_scores(query)

Return docs and relevance scores in the range [0, 1].

similarity_search_with_score(query[, k, ...])

Return docs most similar to query.

similarity_search_with_score_by_vector(embedding)

Return docs most similar to embedding vector.

Parameters
  • client (Any) –

  • collection_name (str) –

  • embeddings (Optional[Embeddings]) –

  • content_payload_key (str) –

  • metadata_payload_key (str) –

  • distance_strategy (str) –

  • vector_name (Optional[str]) –

  • async_client (Optional[Any]) –

  • embedding_function (Optional[Callable]) –

__init__(client: Any, collection_name: str, embeddings: Optional[Embeddings] = None, content_payload_key: str = 'page_content', metadata_payload_key: str = 'metadata', distance_strategy: str = 'COSINE', vector_name: Optional[str] = None, async_client: Optional[Any] = None, embedding_function: Optional[Callable] = None)[source]

Initialize with necessary components.

Parameters
  • client (Any) –

  • collection_name (str) –

  • embeddings (Optional[Embeddings]) –

  • content_payload_key (str) –

  • metadata_payload_key (str) –

  • distance_strategy (str) –

  • vector_name (Optional[str]) –

  • async_client (Optional[Any]) –

  • embedding_function (Optional[Callable]) –

async aadd_documents(documents: List[Document], **kwargs: Any) List[str]

Run more documents through the embeddings and add to the vectorstore.

Parameters
  • documents (List[Document]) – Documents to add to the vectorstore.

  • kwargs (Any) –

Returns

List of IDs of the added texts.

Return type

List[str]

async aadd_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, ids: Optional[Sequence[str]] = None, batch_size: int = 64, **kwargs: Any) List[str][source]

Run more texts through the embeddings and add to the vectorstore.

Parameters
  • texts (Iterable[str]) – Iterable of strings to add to the vectorstore.

  • metadatas (Optional[List[dict]]) – Optional list of metadatas associated with the texts.

  • ids (Optional[Sequence[str]]) – Optional list of ids to associate with the texts. Ids have to be uuid-like strings.

  • batch_size (int) – How many vectors upload per-request. Default: 64

  • kwargs (Any) –

Returns

List of ids from adding the texts into the vectorstore.

Return type

List[str]

async classmethod aconstruct_instance(texts: List[str], embedding: Embeddings, location: Optional[str] = None, url: Optional[str] = None, port: Optional[int] = 6333, grpc_port: int = 6334, prefer_grpc: bool = False, https: Optional[bool] = None, api_key: Optional[str] = None, prefix: Optional[str] = None, timeout: Optional[float] = None, host: Optional[str] = None, path: Optional[str] = None, collection_name: Optional[str] = None, distance_func: str = 'Cosine', content_payload_key: str = 'page_content', metadata_payload_key: str = 'metadata', vector_name: Optional[str] = None, shard_number: Optional[int] = None, replication_factor: Optional[int] = None, write_consistency_factor: Optional[int] = None, on_disk_payload: Optional[bool] = None, hnsw_config: Optional[common_types.HnswConfigDiff] = None, optimizers_config: Optional[common_types.OptimizersConfigDiff] = None, wal_config: Optional[common_types.WalConfigDiff] = None, quantization_config: Optional[common_types.QuantizationConfig] = None, init_from: Optional[common_types.InitFrom] = None, on_disk: Optional[bool] = None, force_recreate: bool = False, **kwargs: Any) Qdrant[source]
Parameters
  • texts (List[str]) –

  • embedding (Embeddings) –

  • location (Optional[str]) –

  • url (Optional[str]) –

  • port (Optional[int]) –

  • grpc_port (int) –

  • prefer_grpc (bool) –

  • https (Optional[bool]) –

  • api_key (Optional[str]) –

  • prefix (Optional[str]) –

  • timeout (Optional[float]) –

  • host (Optional[str]) –

  • path (Optional[str]) –

  • collection_name (Optional[str]) –

  • distance_func (str) –

  • content_payload_key (str) –

  • metadata_payload_key (str) –

  • vector_name (Optional[str]) –

  • shard_number (Optional[int]) –

  • replication_factor (Optional[int]) –

  • write_consistency_factor (Optional[int]) –

  • on_disk_payload (Optional[bool]) –

  • hnsw_config (Optional[common_types.HnswConfigDiff]) –

  • optimizers_config (Optional[common_types.OptimizersConfigDiff]) –

  • wal_config (Optional[common_types.WalConfigDiff]) –

  • quantization_config (Optional[common_types.QuantizationConfig]) –

  • init_from (Optional[common_types.InitFrom]) –

  • on_disk (Optional[bool]) –

  • force_recreate (bool) –

  • kwargs (Any) –

Return type

Qdrant

add_documents(documents: List[Document], **kwargs: Any) List[str]

Run more documents through the embeddings and add to the vectorstore.

Parameters
  • documents (List[Document]) – Documents to add to the vectorstore.

  • kwargs (Any) –

Returns

List of IDs of the added texts.

Return type

List[str]

add_texts(texts: Iterable[str], metadatas: Optional[List[dict]] = None, ids: Optional[Sequence[str]] = None, batch_size: int = 64, **kwargs: Any) List[str][source]

Run more texts through the embeddings and add to the vectorstore.

Parameters
  • texts (Iterable[str]) – Iterable of strings to add to the vectorstore.

  • metadatas (Optional[List[dict]]) – Optional list of metadatas associated with the texts.

  • ids (Optional[Sequence[str]]) – Optional list of ids to associate with the texts. Ids have to be uuid-like strings.

  • batch_size (int) – How many vectors upload per-request. Default: 64

  • kwargs (Any) –

Returns

List of ids from adding the texts into the vectorstore.

Return type

List[str]

async adelete(ids: Optional[List[str]] = None, **kwargs: Any) Optional[bool][source]

Delete by vector ID or other criteria.

Parameters
  • ids (Optional[List[str]]) – List of ids to delete.

  • **kwargs (Any) – Other keyword arguments that subclasses might use.

Returns

True if deletion is successful, False otherwise.

Return type

Optional[bool]

async classmethod afrom_documents(documents: List[Document], embedding: Embeddings, **kwargs: Any) VST

Return VectorStore initialized from documents and embeddings.

Parameters
  • documents (List[Document]) – List of Documents to add to the vectorstore.

  • embedding (Embeddings) – Embedding function to use.

  • kwargs (Any) –

Return type

VST

async classmethod afrom_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, ids: Optional[Sequence[str]] = None, location: Optional[str] = None, url: Optional[str] = None, port: Optional[int] = 6333, grpc_port: int = 6334, prefer_grpc: bool = False, https: Optional[bool] = None, api_key: Optional[str] = None, prefix: Optional[str] = None, timeout: Optional[float] = None, host: Optional[str] = None, path: Optional[str] = None, collection_name: Optional[str] = None, distance_func: str = 'Cosine', content_payload_key: str = 'page_content', metadata_payload_key: str = 'metadata', vector_name: Optional[str] = None, batch_size: int = 64, shard_number: Optional[int] = None, replication_factor: Optional[int] = None, write_consistency_factor: Optional[int] = None, on_disk_payload: Optional[bool] = None, hnsw_config: Optional[common_types.HnswConfigDiff] = None, optimizers_config: Optional[common_types.OptimizersConfigDiff] = None, wal_config: Optional[common_types.WalConfigDiff] = None, quantization_config: Optional[common_types.QuantizationConfig] = None, init_from: Optional[common_types.InitFrom] = None, on_disk: Optional[bool] = None, force_recreate: bool = False, **kwargs: Any) Qdrant[source]

Construct Qdrant wrapper from a list of texts.

Parameters
  • texts (List[str]) – A list of texts to be indexed in Qdrant.

  • embedding (Embeddings) – A subclass of Embeddings, responsible for text vectorization.

  • metadatas (Optional[List[dict]]) – An optional list of metadata. If provided it has to be of the same length as a list of texts.

  • ids (Optional[Sequence[str]]) – Optional list of ids to associate with the texts. Ids have to be uuid-like strings.

  • location (Optional[str]) – If :memory: - use in-memory Qdrant instance. If str - use it as a url parameter. If None - fallback to relying on host and port parameters.

  • url (Optional[str]) – either host or str of “Optional[scheme], host, Optional[port], Optional[prefix]”. Default: None

  • port (Optional[int]) – Port of the REST API interface. Default: 6333

  • grpc_port (int) – Port of the gRPC interface. Default: 6334

  • prefer_grpc (bool) – If true - use gPRC interface whenever possible in custom methods. Default: False

  • https (Optional[bool]) – If true - use HTTPS(SSL) protocol. Default: None

  • api_key (Optional[str]) – API key for authentication in Qdrant Cloud. Default: None

  • prefix (Optional[str]) –

    If not None - add prefix to the REST URL path. Example: service/v1 will result in

    http://localhost:6333/service/v1/{qdrant-endpoint} for REST API.

    Default: None

  • timeout (Optional[float]) – Timeout for REST and gRPC API requests. Default: 5.0 seconds for REST and unlimited for gRPC

  • host (Optional[str]) – Host name of Qdrant service. If url and host are None, set to ‘localhost’. Default: None

  • path (Optional[str]) – Path in which the vectors will be stored while using local mode. Default: None

  • collection_name (Optional[str]) – Name of the Qdrant collection to be used. If not provided, it will be created randomly. Default: None

  • distance_func (str) – Distance function. One of: “Cosine” / “Euclid” / “Dot”. Default: “Cosine”

  • content_payload_key (str) – A payload key used to store the content of the document. Default: “page_content”

  • metadata_payload_key (str) – A payload key used to store the metadata of the document. Default: “metadata”

  • vector_name (Optional[str]) – Name of the vector to be used internally in Qdrant. Default: None

  • batch_size (int) – How many vectors upload per-request. Default: 64

  • shard_number (Optional[int]) – Number of shards in collection. Default is 1, minimum is 1.

  • replication_factor (Optional[int]) – Replication factor for collection. Default is 1, minimum is 1. Defines how many copies of each shard will be created. Have effect only in distributed mode.

  • write_consistency_factor (Optional[int]) – Write consistency factor for collection. Default is 1, minimum is 1. Defines how many replicas should apply the operation for us to consider it successful. Increasing this number will make the collection more resilient to inconsistencies, but will also make it fail if not enough replicas are available. Does not have any performance impact. Have effect only in distributed mode.

  • on_disk_payload (Optional[bool]) – If true - point`s payload will not be stored in memory. It will be read from the disk every time it is requested. This setting saves RAM by (slightly) increasing the response time. Note: those payload values that are involved in filtering and are indexed - remain in RAM.

  • hnsw_config (Optional[common_types.HnswConfigDiff]) – Params for HNSW index

  • optimizers_config (Optional[common_types.OptimizersConfigDiff]) – Params for optimizer

  • wal_config (Optional[common_types.WalConfigDiff]) – Params for Write-Ahead-Log

  • quantization_config (Optional[common_types.QuantizationConfig]) – Params for quantization, if None - quantization will be disabled

  • init_from (Optional[common_types.InitFrom]) – Use data stored in another collection to initialize this collection

  • force_recreate (bool) – Force recreating the collection

  • **kwargs (Any) – Additional arguments passed directly into REST client initialization

  • on_disk (Optional[bool]) –

Return type

Qdrant

This is a user-friendly interface that: 1. Creates embeddings, one for each text 2. Initializes the Qdrant database as an in-memory docstore by default

(and overridable to a remote docstore)

  1. Adds the text embeddings to the Qdrant database

This is intended to be a quick way to get started.

Example

from langchain_community.vectorstores import Qdrant
from langchain_community.embeddings import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
qdrant = await Qdrant.afrom_texts(texts, embeddings, "localhost")

Return docs selected using the maximal marginal relevance.

Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.

Parameters
  • query (str) – Text to look up documents similar to.

  • k (int) – Number of Documents to return. Defaults to 4.

  • fetch_k (int) – Number of Documents to fetch to pass to MMR algorithm. Defaults to 20.

  • lambda_mult (float) – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5.

  • filter (Optional[MetadataFilter]) – Filter by metadata. Defaults to None.

  • search_params (Optional[common_types.SearchParams]) – Additional search params

  • score_threshold (Optional[float]) – Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned.

  • consistency (Optional[common_types.ReadConsistency]) –

    Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all

    queried replicas

    • ’majority’ - query all replicas, but return values present in the

      majority of replicas

    • ’quorum’ - query the majority of replicas, return values present in

      all of them

    • ’all’ - query all replicas, and return values present in all replicas

  • **kwargs (Any) – Any other named arguments to pass through to AsyncQdrantClient.Search().

Returns

List of Documents selected by maximal marginal relevance.

Return type

List[Document]

async amax_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[MetadataFilter] = None, search_params: Optional[common_types.SearchParams] = None, score_threshold: Optional[float] = None, consistency: Optional[common_types.ReadConsistency] = None, **kwargs: Any) List[Document][source]

Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. :param query: Text to look up documents similar to. :param k: Number of Documents to return. Defaults to 4. :param fetch_k: Number of Documents to fetch to pass to MMR algorithm.

Defaults to 20.

Parameters
  • lambda_mult (float) – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5.

  • filter (Optional[MetadataFilter]) – Filter by metadata. Defaults to None.

  • search_params (Optional[common_types.SearchParams]) – Additional search params

  • score_threshold (Optional[float]) – Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned.

  • consistency (Optional[common_types.ReadConsistency]) –

    Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all

    queried replicas

    • ’majority’ - query all replicas, but return values present in the

      majority of replicas

    • ’quorum’ - query the majority of replicas, return values present in

      all of them

    • ’all’ - query all replicas, and return values present in all replicas

  • **kwargs (Any) – Any other named arguments to pass through to AsyncQdrantClient.Search().

  • embedding (List[float]) –

  • k (int) –

  • fetch_k (int) –

Returns

List of Documents selected by maximal marginal relevance and distance for each.

Return type

List[Document]

async amax_marginal_relevance_search_with_score_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[MetadataFilter] = None, search_params: Optional[common_types.SearchParams] = None, score_threshold: Optional[float] = None, consistency: Optional[common_types.ReadConsistency] = None, **kwargs: Any) List[Tuple[Document, float]][source]

Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. :param query: Text to look up documents similar to. :param k: Number of Documents to return. Defaults to 4. :param fetch_k: Number of Documents to fetch to pass to MMR algorithm.

Defaults to 20.

Parameters
  • lambda_mult (float) – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5.

  • embedding (List[float]) –

  • k (int) –

  • fetch_k (int) –

  • filter (Optional[MetadataFilter]) –

  • search_params (Optional[common_types.SearchParams]) –

  • score_threshold (Optional[float]) –

  • consistency (Optional[common_types.ReadConsistency]) –

  • kwargs (Any) –

Returns

List of Documents selected by maximal marginal relevance and distance for each.

Return type

List[Tuple[Document, float]]

as_retriever(**kwargs: Any) VectorStoreRetriever

Return VectorStoreRetriever initialized from this VectorStore.

Parameters
  • search_type (Optional[str]) – Defines the type of search that the Retriever should perform. Can be “similarity” (default), “mmr”, or “similarity_score_threshold”.

  • search_kwargs (Optional[Dict]) –

    Keyword arguments to pass to the search function. Can include things like:

    k: Amount of documents to return (Default: 4) score_threshold: Minimum relevance threshold

    for similarity_score_threshold

    fetch_k: Amount of documents to pass to MMR algorithm (Default: 20) lambda_mult: Diversity of results returned by MMR;

    1 for minimum diversity and 0 for maximum. (Default: 0.5)

    filter: Filter by document metadata

  • kwargs (Any) –

Returns

Retriever class for VectorStore.

Return type

VectorStoreRetriever

Examples:

# Retrieve more documents with higher diversity
# Useful if your dataset has many similar documents
docsearch.as_retriever(
    search_type="mmr",
    search_kwargs={'k': 6, 'lambda_mult': 0.25}
)

# Fetch more documents for the MMR algorithm to consider
# But only return the top 5
docsearch.as_retriever(
    search_type="mmr",
    search_kwargs={'k': 5, 'fetch_k': 50}
)

# Only retrieve documents that have a relevance score
# Above a certain threshold
docsearch.as_retriever(
    search_type="similarity_score_threshold",
    search_kwargs={'score_threshold': 0.8}
)

# Only get the single most similar document from the dataset
docsearch.as_retriever(search_kwargs={'k': 1})

# Use a filter to only retrieve documents from a specific paper
docsearch.as_retriever(
    search_kwargs={'filter': {'paper_title':'GPT-4 Technical Report'}}
)
async asearch(query: str, search_type: str, **kwargs: Any) List[Document]

Return docs most similar to query using specified search type.

Parameters
  • query (str) – Input text.

  • search_type (str) – Type of search to perform. Can be “similarity”, “mmr”, or “similarity_score_threshold”.

  • **kwargs (Any) – Arguments to pass to the search method.

Return type

List[Document]

Return docs most similar to query. :param query: Text to look up documents similar to. :param k: Number of Documents to return. Defaults to 4. :param filter: Filter by metadata. Defaults to None.

Returns

List of Documents most similar to the query.

Parameters
  • query (str) –

  • k (int) –

  • filter (Optional[MetadataFilter]) –

  • kwargs (Any) –

Return type

List[Document]

async asimilarity_search_by_vector(embedding: List[float], k: int = 4, filter: Optional[MetadataFilter] = None, search_params: Optional[common_types.SearchParams] = None, offset: int = 0, score_threshold: Optional[float] = None, consistency: Optional[common_types.ReadConsistency] = None, **kwargs: Any) List[Document][source]

Return docs most similar to embedding vector.

Parameters
  • embedding (List[float]) – Embedding vector to look up documents similar to.

  • k (int) – Number of Documents to return. Defaults to 4.

  • filter (Optional[MetadataFilter]) – Filter by metadata. Defaults to None.

  • search_params (Optional[common_types.SearchParams]) – Additional search params

  • offset (int) – Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues.

  • score_threshold (Optional[float]) – Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned.

  • consistency (Optional[common_types.ReadConsistency]) –

    Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all

    queried replicas

    • ’majority’ - query all replicas, but return values present in the

      majority of replicas

    • ’quorum’ - query the majority of replicas, return values present in

      all of them

    • ’all’ - query all replicas, and return values present in all replicas

  • **kwargs (Any) – Any other named arguments to pass through to AsyncQdrantClient.Search().

Returns

List of Documents most similar to the query.

Return type

List[Document]

async asimilarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) List[Tuple[Document, float]]

Return docs and relevance scores in the range [0, 1].

0 is dissimilar, 1 is most similar.

Parameters
  • query (str) – Input text.

  • k (int) – Number of Documents to return. Defaults to 4.

  • **kwargs (Any) –

    kwargs to be passed to similarity search. Should include: score_threshold: Optional, a floating point value between 0 to 1 to

    filter the resulting set of retrieved docs

Returns

List of Tuples of (doc, similarity_score)

Return type

List[Tuple[Document, float]]

async asimilarity_search_with_score(query: str, k: int = 4, filter: Optional[MetadataFilter] = None, search_params: Optional[common_types.SearchParams] = None, offset: int = 0, score_threshold: Optional[float] = None, consistency: Optional[common_types.ReadConsistency] = None, **kwargs: Any) List[Tuple[Document, float]][source]

Return docs most similar to query.

Parameters
  • query (str) – Text to look up documents similar to.

  • k (int) – Number of Documents to return. Defaults to 4.

  • filter (Optional[MetadataFilter]) – Filter by metadata. Defaults to None.

  • search_params (Optional[common_types.SearchParams]) – Additional search params

  • offset (int) – Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues.

  • score_threshold (Optional[float]) – Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned.

  • consistency (Optional[common_types.ReadConsistency]) –

    Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all

    queried replicas

    • ’majority’ - query all replicas, but return values present in the

      majority of replicas

    • ’quorum’ - query the majority of replicas, return values present in

      all of them

    • ’all’ - query all replicas, and return values present in all replicas

  • **kwargs (Any) – Any other named arguments to pass through to AsyncQdrantClient.Search().

Returns

List of documents most similar to the query text and distance for each.

Return type

List[Tuple[Document, float]]

async asimilarity_search_with_score_by_vector(embedding: List[float], k: int = 4, filter: Optional[MetadataFilter] = None, search_params: Optional[common_types.SearchParams] = None, offset: int = 0, score_threshold: Optional[float] = None, consistency: Optional[common_types.ReadConsistency] = None, **kwargs: Any) List[Tuple[Document, float]][source]

Return docs most similar to embedding vector.

Parameters
  • embedding (List[float]) – Embedding vector to look up documents similar to.

  • k (int) – Number of Documents to return. Defaults to 4.

  • filter (Optional[MetadataFilter]) – Filter by metadata. Defaults to None.

  • search_params (Optional[common_types.SearchParams]) – Additional search params

  • offset (int) – Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues.

  • score_threshold (Optional[float]) – Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned.

  • consistency (Optional[common_types.ReadConsistency]) –

    Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all

    queried replicas

    • ’majority’ - query all replicas, but return values present in the

      majority of replicas

    • ’quorum’ - query the majority of replicas, return values present in

      all of them

    • ’all’ - query all replicas, and return values present in all replicas

  • **kwargs (Any) – Any other named arguments to pass through to AsyncQdrantClient.Search().

Returns

List of documents most similar to the query text and distance for each.

Return type

List[Tuple[Document, float]]

classmethod construct_instance(texts: List[str], embedding: Embeddings, location: Optional[str] = None, url: Optional[str] = None, port: Optional[int] = 6333, grpc_port: int = 6334, prefer_grpc: bool = False, https: Optional[bool] = None, api_key: Optional[str] = None, prefix: Optional[str] = None, timeout: Optional[float] = None, host: Optional[str] = None, path: Optional[str] = None, collection_name: Optional[str] = None, distance_func: str = 'Cosine', content_payload_key: str = 'page_content', metadata_payload_key: str = 'metadata', vector_name: Optional[str] = None, shard_number: Optional[int] = None, replication_factor: Optional[int] = None, write_consistency_factor: Optional[int] = None, on_disk_payload: Optional[bool] = None, hnsw_config: Optional[common_types.HnswConfigDiff] = None, optimizers_config: Optional[common_types.OptimizersConfigDiff] = None, wal_config: Optional[common_types.WalConfigDiff] = None, quantization_config: Optional[common_types.QuantizationConfig] = None, init_from: Optional[common_types.InitFrom] = None, on_disk: Optional[bool] = None, force_recreate: bool = False, **kwargs: Any) Qdrant[source]
Parameters
  • texts (List[str]) –

  • embedding (Embeddings) –

  • location (Optional[str]) –

  • url (Optional[str]) –

  • port (Optional[int]) –

  • grpc_port (int) –

  • prefer_grpc (bool) –

  • https (Optional[bool]) –

  • api_key (Optional[str]) –

  • prefix (Optional[str]) –

  • timeout (Optional[float]) –

  • host (Optional[str]) –

  • path (Optional[str]) –

  • collection_name (Optional[str]) –

  • distance_func (str) –

  • content_payload_key (str) –

  • metadata_payload_key (str) –

  • vector_name (Optional[str]) –

  • shard_number (Optional[int]) –

  • replication_factor (Optional[int]) –

  • write_consistency_factor (Optional[int]) –

  • on_disk_payload (Optional[bool]) –

  • hnsw_config (Optional[common_types.HnswConfigDiff]) –

  • optimizers_config (Optional[common_types.OptimizersConfigDiff]) –

  • wal_config (Optional[common_types.WalConfigDiff]) –

  • quantization_config (Optional[common_types.QuantizationConfig]) –

  • init_from (Optional[common_types.InitFrom]) –

  • on_disk (Optional[bool]) –

  • force_recreate (bool) –

  • kwargs (Any) –

Return type

Qdrant

delete(ids: Optional[List[str]] = None, **kwargs: Any) Optional[bool][source]

Delete by vector ID or other criteria.

Parameters
  • ids (Optional[List[str]]) – List of ids to delete.

  • **kwargs (Any) – Other keyword arguments that subclasses might use.

Returns

True if deletion is successful, False otherwise.

Return type

Optional[bool]

classmethod from_documents(documents: List[Document], embedding: Embeddings, **kwargs: Any) VST

Return VectorStore initialized from documents and embeddings.

Parameters
  • documents (List[Document]) – List of Documents to add to the vectorstore.

  • embedding (Embeddings) – Embedding function to use.

  • kwargs (Any) –

Return type

VST

classmethod from_existing_collection(embedding: Embeddings, path: str, collection_name: str, location: Optional[str] = None, url: Optional[str] = None, port: Optional[int] = 6333, grpc_port: int = 6334, prefer_grpc: bool = False, https: Optional[bool] = None, api_key: Optional[str] = None, prefix: Optional[str] = None, timeout: Optional[float] = None, host: Optional[str] = None, **kwargs: Any) Qdrant[source]

Get instance of an existing Qdrant collection. This method will return the instance of the store without inserting any new embeddings

Parameters
  • embedding (Embeddings) –

  • path (str) –

  • collection_name (str) –

  • location (Optional[str]) –

  • url (Optional[str]) –

  • port (Optional[int]) –

  • grpc_port (int) –

  • prefer_grpc (bool) –

  • https (Optional[bool]) –

  • api_key (Optional[str]) –

  • prefix (Optional[str]) –

  • timeout (Optional[float]) –

  • host (Optional[str]) –

  • kwargs (Any) –

Return type

Qdrant

classmethod from_texts(texts: List[str], embedding: Embeddings, metadatas: Optional[List[dict]] = None, ids: Optional[Sequence[str]] = None, location: Optional[str] = None, url: Optional[str] = None, port: Optional[int] = 6333, grpc_port: int = 6334, prefer_grpc: bool = False, https: Optional[bool] = None, api_key: Optional[str] = None, prefix: Optional[str] = None, timeout: Optional[float] = None, host: Optional[str] = None, path: Optional[str] = None, collection_name: Optional[str] = None, distance_func: str = 'Cosine', content_payload_key: str = 'page_content', metadata_payload_key: str = 'metadata', vector_name: Optional[str] = None, batch_size: int = 64, shard_number: Optional[int] = None, replication_factor: Optional[int] = None, write_consistency_factor: Optional[int] = None, on_disk_payload: Optional[bool] = None, hnsw_config: Optional[common_types.HnswConfigDiff] = None, optimizers_config: Optional[common_types.OptimizersConfigDiff] = None, wal_config: Optional[common_types.WalConfigDiff] = None, quantization_config: Optional[common_types.QuantizationConfig] = None, init_from: Optional[common_types.InitFrom] = None, on_disk: Optional[bool] = None, force_recreate: bool = False, **kwargs: Any) Qdrant[source]

Construct Qdrant wrapper from a list of texts.

Parameters
  • texts (List[str]) – A list of texts to be indexed in Qdrant.

  • embedding (Embeddings) – A subclass of Embeddings, responsible for text vectorization.

  • metadatas (Optional[List[dict]]) – An optional list of metadata. If provided it has to be of the same length as a list of texts.

  • ids (Optional[Sequence[str]]) – Optional list of ids to associate with the texts. Ids have to be uuid-like strings.

  • location (Optional[str]) – If :memory: - use in-memory Qdrant instance. If str - use it as a url parameter. If None - fallback to relying on host and port parameters.

  • url (Optional[str]) – either host or str of “Optional[scheme], host, Optional[port], Optional[prefix]”. Default: None

  • port (Optional[int]) – Port of the REST API interface. Default: 6333

  • grpc_port (int) – Port of the gRPC interface. Default: 6334

  • prefer_grpc (bool) – If true - use gPRC interface whenever possible in custom methods. Default: False

  • https (Optional[bool]) – If true - use HTTPS(SSL) protocol. Default: None

  • api_key (Optional[str]) – API key for authentication in Qdrant Cloud. Default: None

  • prefix (Optional[str]) –

    If not None - add prefix to the REST URL path. Example: service/v1 will result in

    http://localhost:6333/service/v1/{qdrant-endpoint} for REST API.

    Default: None

  • timeout (Optional[float]) – Timeout for REST and gRPC API requests. Default: 5.0 seconds for REST and unlimited for gRPC

  • host (Optional[str]) – Host name of Qdrant service. If url and host are None, set to ‘localhost’. Default: None

  • path (Optional[str]) – Path in which the vectors will be stored while using local mode. Default: None

  • collection_name (Optional[str]) – Name of the Qdrant collection to be used. If not provided, it will be created randomly. Default: None

  • distance_func (str) – Distance function. One of: “Cosine” / “Euclid” / “Dot”. Default: “Cosine”

  • content_payload_key (str) – A payload key used to store the content of the document. Default: “page_content”

  • metadata_payload_key (str) – A payload key used to store the metadata of the document. Default: “metadata”

  • vector_name (Optional[str]) – Name of the vector to be used internally in Qdrant. Default: None

  • batch_size (int) – How many vectors upload per-request. Default: 64

  • shard_number (Optional[int]) – Number of shards in collection. Default is 1, minimum is 1.

  • replication_factor (Optional[int]) – Replication factor for collection. Default is 1, minimum is 1. Defines how many copies of each shard will be created. Have effect only in distributed mode.

  • write_consistency_factor (Optional[int]) – Write consistency factor for collection. Default is 1, minimum is 1. Defines how many replicas should apply the operation for us to consider it successful. Increasing this number will make the collection more resilient to inconsistencies, but will also make it fail if not enough replicas are available. Does not have any performance impact. Have effect only in distributed mode.

  • on_disk_payload (Optional[bool]) – If true - point`s payload will not be stored in memory. It will be read from the disk every time it is requested. This setting saves RAM by (slightly) increasing the response time. Note: those payload values that are involved in filtering and are indexed - remain in RAM.

  • hnsw_config (Optional[common_types.HnswConfigDiff]) – Params for HNSW index

  • optimizers_config (Optional[common_types.OptimizersConfigDiff]) – Params for optimizer

  • wal_config (Optional[common_types.WalConfigDiff]) – Params for Write-Ahead-Log

  • quantization_config (Optional[common_types.QuantizationConfig]) – Params for quantization, if None - quantization will be disabled

  • init_from (Optional[common_types.InitFrom]) – Use data stored in another collection to initialize this collection

  • force_recreate (bool) – Force recreating the collection

  • **kwargs (Any) – Additional arguments passed directly into REST client initialization

  • on_disk (Optional[bool]) –

Return type

Qdrant

This is a user-friendly interface that: 1. Creates embeddings, one for each text 2. Initializes the Qdrant database as an in-memory docstore by default

(and overridable to a remote docstore)

  1. Adds the text embeddings to the Qdrant database

This is intended to be a quick way to get started.

Example

from langchain_community.vectorstores import Qdrant
from langchain_community.embeddings import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
qdrant = Qdrant.from_texts(texts, embeddings, "localhost")

Return docs selected using the maximal marginal relevance.

Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.

Parameters
  • query (str) – Text to look up documents similar to.

  • k (int) – Number of Documents to return. Defaults to 4.

  • fetch_k (int) – Number of Documents to fetch to pass to MMR algorithm. Defaults to 20.

  • lambda_mult (float) – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5.

  • filter (Optional[MetadataFilter]) – Filter by metadata. Defaults to None.

  • search_params (Optional[common_types.SearchParams]) – Additional search params

  • score_threshold (Optional[float]) – Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned.

  • consistency (Optional[common_types.ReadConsistency]) –

    Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all

    queried replicas

    • ’majority’ - query all replicas, but return values present in the

      majority of replicas

    • ’quorum’ - query the majority of replicas, return values present in

      all of them

    • ’all’ - query all replicas, and return values present in all replicas

  • **kwargs (Any) – Any other named arguments to pass through to QdrantClient.search()

Returns

List of Documents selected by maximal marginal relevance.

Return type

List[Document]

max_marginal_relevance_search_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[MetadataFilter] = None, search_params: Optional[common_types.SearchParams] = None, score_threshold: Optional[float] = None, consistency: Optional[common_types.ReadConsistency] = None, **kwargs: Any) List[Document][source]

Return docs selected using the maximal marginal relevance.

Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.

Parameters
  • embedding (List[float]) – Embedding to look up documents similar to.

  • k (int) – Number of Documents to return. Defaults to 4.

  • fetch_k (int) – Number of Documents to fetch to pass to MMR algorithm.

  • lambda_mult (float) – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5.

  • filter (Optional[MetadataFilter]) – Filter by metadata. Defaults to None.

  • search_params (Optional[common_types.SearchParams]) – Additional search params

  • score_threshold (Optional[float]) – Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned.

  • consistency (Optional[common_types.ReadConsistency]) –

    Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all

    queried replicas

    • ’majority’ - query all replicas, but return values present in the

      majority of replicas

    • ’quorum’ - query the majority of replicas, return values present in

      all of them

    • ’all’ - query all replicas, and return values present in all replicas

  • **kwargs (Any) – Any other named arguments to pass through to QdrantClient.search()

Returns

List of Documents selected by maximal marginal relevance.

Return type

List[Document]

max_marginal_relevance_search_with_score_by_vector(embedding: List[float], k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[MetadataFilter] = None, search_params: Optional[common_types.SearchParams] = None, score_threshold: Optional[float] = None, consistency: Optional[common_types.ReadConsistency] = None, **kwargs: Any) List[Tuple[Document, float]][source]

Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. :param query: Text to look up documents similar to. :param k: Number of Documents to return. Defaults to 4. :param fetch_k: Number of Documents to fetch to pass to MMR algorithm.

Defaults to 20.

Parameters
  • lambda_mult (float) – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5.

  • filter (Optional[MetadataFilter]) – Filter by metadata. Defaults to None.

  • search_params (Optional[common_types.SearchParams]) – Additional search params

  • score_threshold (Optional[float]) – Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned.

  • consistency (Optional[common_types.ReadConsistency]) –

    Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all

    queried replicas

    • ’majority’ - query all replicas, but return values present in the

      majority of replicas

    • ’quorum’ - query the majority of replicas, return values present in

      all of them

    • ’all’ - query all replicas, and return values present in all replicas

  • **kwargs (Any) – Any other named arguments to pass through to QdrantClient.search()

  • embedding (List[float]) –

  • k (int) –

  • fetch_k (int) –

Returns

List of Documents selected by maximal marginal relevance and distance for each.

Return type

List[Tuple[Document, float]]

search(query: str, search_type: str, **kwargs: Any) List[Document]

Return docs most similar to query using specified search type.

Parameters
  • query (str) – Input text

  • search_type (str) – Type of search to perform. Can be “similarity”, “mmr”, or “similarity_score_threshold”.

  • **kwargs (Any) – Arguments to pass to the search method.

Return type

List[Document]

Return docs most similar to query.

Parameters
  • query (str) – Text to look up documents similar to.

  • k (int) – Number of Documents to return. Defaults to 4.

  • filter (Optional[MetadataFilter]) – Filter by metadata. Defaults to None.

  • search_params (Optional[common_types.SearchParams]) – Additional search params

  • offset (int) – Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues.

  • score_threshold (Optional[float]) – Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned.

  • consistency (Optional[common_types.ReadConsistency]) –

    Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all

    queried replicas

    • ’majority’ - query all replicas, but return values present in the

      majority of replicas

    • ’quorum’ - query the majority of replicas, return values present in

      all of them

    • ’all’ - query all replicas, and return values present in all replicas

  • **kwargs (Any) – Any other named arguments to pass through to QdrantClient.search()

Returns

List of Documents most similar to the query.

Return type

List[Document]

similarity_search_by_vector(embedding: List[float], k: int = 4, filter: Optional[MetadataFilter] = None, search_params: Optional[common_types.SearchParams] = None, offset: int = 0, score_threshold: Optional[float] = None, consistency: Optional[common_types.ReadConsistency] = None, **kwargs: Any) List[Document][source]

Return docs most similar to embedding vector.

Parameters
  • embedding (List[float]) – Embedding vector to look up documents similar to.

  • k (int) – Number of Documents to return. Defaults to 4.

  • filter (Optional[MetadataFilter]) – Filter by metadata. Defaults to None.

  • search_params (Optional[common_types.SearchParams]) – Additional search params

  • offset (int) – Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues.

  • score_threshold (Optional[float]) – Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned.

  • consistency (Optional[common_types.ReadConsistency]) –

    Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all

    queried replicas

    • ’majority’ - query all replicas, but return values present in the

      majority of replicas

    • ’quorum’ - query the majority of replicas, return values present in

      all of them

    • ’all’ - query all replicas, and return values present in all replicas

  • **kwargs (Any) – Any other named arguments to pass through to QdrantClient.search()

Returns

List of Documents most similar to the query.

Return type

List[Document]

similarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) List[Tuple[Document, float]]

Return docs and relevance scores in the range [0, 1].

0 is dissimilar, 1 is most similar.

Parameters
  • query (str) – Input text.

  • k (int) – Number of Documents to return. Defaults to 4.

  • **kwargs (Any) –

    kwargs to be passed to similarity search. Should include: score_threshold: Optional, a floating point value between 0 to 1 to

    filter the resulting set of retrieved docs

Returns

List of Tuples of (doc, similarity_score)

Return type

List[Tuple[Document, float]]

similarity_search_with_score(query: str, k: int = 4, filter: Optional[MetadataFilter] = None, search_params: Optional[common_types.SearchParams] = None, offset: int = 0, score_threshold: Optional[float] = None, consistency: Optional[common_types.ReadConsistency] = None, **kwargs: Any) List[Tuple[Document, float]][source]

Return docs most similar to query.

Parameters
  • query (str) – Text to look up documents similar to.

  • k (int) – Number of Documents to return. Defaults to 4.

  • filter (Optional[MetadataFilter]) – Filter by metadata. Defaults to None.

  • search_params (Optional[common_types.SearchParams]) – Additional search params

  • offset (int) – Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues.

  • score_threshold (Optional[float]) – Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned.

  • consistency (Optional[common_types.ReadConsistency]) –

    Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all

    queried replicas

    • ’majority’ - query all replicas, but return values present in the

      majority of replicas

    • ’quorum’ - query the majority of replicas, return values present in

      all of them

    • ’all’ - query all replicas, and return values present in all replicas

  • **kwargs (Any) – Any other named arguments to pass through to QdrantClient.search()

Returns

List of documents most similar to the query text and distance for each.

Return type

List[Tuple[Document, float]]

similarity_search_with_score_by_vector(embedding: List[float], k: int = 4, filter: Optional[MetadataFilter] = None, search_params: Optional[common_types.SearchParams] = None, offset: int = 0, score_threshold: Optional[float] = None, consistency: Optional[common_types.ReadConsistency] = None, **kwargs: Any) List[Tuple[Document, float]][source]

Return docs most similar to embedding vector.

Parameters
  • embedding (List[float]) – Embedding vector to look up documents similar to.

  • k (int) – Number of Documents to return. Defaults to 4.

  • filter (Optional[MetadataFilter]) – Filter by metadata. Defaults to None.

  • search_params (Optional[common_types.SearchParams]) – Additional search params

  • offset (int) – Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues.

  • score_threshold (Optional[float]) – Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned.

  • consistency (Optional[common_types.ReadConsistency]) –

    Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all

    queried replicas

    • ’majority’ - query all replicas, but return values present in the

      majority of replicas

    • ’quorum’ - query the majority of replicas, return values present in

      all of them

    • ’all’ - query all replicas, and return values present in all replicas

  • **kwargs (Any) – Any other named arguments to pass through to QdrantClient.search()

Returns

List of documents most similar to the query text and distance for each.

Return type

List[Tuple[Document, float]]

Examples using Qdrant