这是indexloc提供的服务,不要输入任何密码
Skip to content

langchain-qdrant

PyPI - Version PyPI - License PyPI - Downloads

Reference docs

This page contains reference documentation for Qdrant. See the docs for conceptual guides, tutorials, and examples on using Qdrant modules.

langchain_qdrant

FastEmbedSparse

Bases: SparseEmbeddings

An interface for sparse embedding models to use with Qdrant.

METHOD DESCRIPTION
aembed_documents

Asynchronous Embed search docs.

aembed_query

Asynchronous Embed query text.

__init__

Sparse encoder implementation using FastEmbed.

embed_documents

Embed search docs.

embed_query

Embed query text.

aembed_documents async

aembed_documents(texts: list[str]) -> list[SparseVector]

Asynchronous Embed search docs.

aembed_query async

aembed_query(text: str) -> SparseVector

Asynchronous Embed query text.

__init__

__init__(
    model_name: str = "Qdrant/bm25",
    batch_size: int = 256,
    cache_dir: str | None = None,
    threads: int | None = None,
    providers: Sequence[Any] | None = None,
    parallel: int | None = None,
    **kwargs: Any,
) -> None

Sparse encoder implementation using FastEmbed.

Uses FastEmbed for sparse text embeddings. For a list of available models, see the Qdrant docs.

PARAMETER DESCRIPTION
model_name

The name of the model to use.

TYPE: str DEFAULT: 'Qdrant/bm25'

batch_size

Batch size for encoding.

TYPE: int DEFAULT: 256

cache_dir

The path to the model cache directory. Can also be set using the FASTEMBED_CACHE_PATH env variable.

TYPE: str DEFAULT: None

threads

The number of threads onnxruntime session can use.

TYPE: int DEFAULT: None

providers

List of ONNX execution providers. parallel (int, optional): If >1, data-parallel encoding will be used, r Recommended for encoding of large datasets. If 0, use all available cores. If None, don't use data-parallel processing, use default onnxruntime threading instead.

TYPE: Sequence[Any] DEFAULT: None

kwargs

Additional options to pass to fastembed.SparseTextEmbedding

TYPE: Any DEFAULT: {}

RAISES DESCRIPTION
ValueError

If the model_name is not supported in SparseTextEmbedding.

embed_documents

embed_documents(texts: list[str]) -> list[SparseVector]

Embed search docs.

embed_query

embed_query(text: str) -> SparseVector

Embed query text.

QdrantVectorStore

Bases: VectorStore

Qdrant vector store integration.

Setup

Install langchain-qdrant package.

pip install -qU langchain-qdrant

Key init args — indexing params: collection_name: Name of the collection. embedding: Embedding function to use. sparse_embedding: Optional sparse embedding function to use.

Key init args — client params: client: Qdrant client to use. retrieval_mode: Retrieval mode to use.

Instantiate
from langchain_qdrant import QdrantVectorStore
from qdrant_client import QdrantClient
from qdrant_client.http.models import Distance, VectorParams
from langchain_openai import OpenAIEmbeddings

client = QdrantClient(":memory:")

client.create_collection(
    collection_name="demo_collection",
    vectors_config=VectorParams(size=1536, distance=Distance.COSINE),
)

vector_store = QdrantVectorStore(
    client=client,
    collection_name="demo_collection",
    embedding=OpenAIEmbeddings(),
)
Add Documents
from langchain_core.documents import Document
from uuid import uuid4

document_1 = Document(page_content="foo", metadata={"baz": "bar"})
document_2 = Document(page_content="thud", metadata={"bar": "baz"})
document_3 = Document(page_content="i will be deleted :(")

documents = [document_1, document_2, document_3]
ids = [str(uuid4()) for _ in range(len(documents))]
vector_store.add_documents(documents=documents, ids=ids)
Delete Documents
vector_store.delete(ids=[ids[-1]])
Search with filter
from qdrant_client.http import models

results = vector_store.similarity_search(
    query="thud",
    k=1,
    filter=models.Filter(
        must=[
            models.FieldCondition(
                key="metadata.bar",
                match=models.MatchValue(value="baz"),
            )
        ]
    ),
)
for doc in results:
    print(f"* {doc.page_content} [{doc.metadata}]")
*thud[
    {
        "bar": "baz",
        "_id": "0d706099-6dd9-412a-9df6-a71043e020de",
        "_collection_name": "demo_collection",
    }
]
Search with score
results = vector_store.similarity_search_with_score(query="qux", k=1)
for doc, score in results:
    print(f"* [SIM={score:3f}] {doc.page_content} [{doc.metadata}]")
* [SIM=0.832268] foo [{'baz': 'bar', '_id': '44ec7094-b061-45ac-8fbf-014b0f18e8aa', '_collection_name': 'demo_collection'}]
Async
# add documents
# await vector_store.aadd_documents(documents=documents, ids=ids)

# delete documents
# await vector_store.adelete(ids=["3"])

# search
# results = vector_store.asimilarity_search(query="thud",k=1)

# search with score
results = await vector_store.asimilarity_search_with_score(query="qux", k=1)
for doc, score in results:
    print(f"* [SIM={score:3f}] {doc.page_content} [{doc.metadata}]")
* [SIM=0.832268] foo [{'baz': 'bar', '_id': '44ec7094-b061-45ac-8fbf-014b0f18e8aa', '_collection_name': 'demo_collection'}]
Use as Retriever
retriever = vector_store.as_retriever(
    search_type="mmr",
    search_kwargs={"k": 1, "fetch_k": 2, "lambda_mult": 0.5},
)
retriever.invoke("thud")
[
    Document(
        metadata={
            "bar": "baz",
            "_id": "0d706099-6dd9-412a-9df6-a71043e020de",
            "_collection_name": "demo_collection",
        },
        page_content="thud",
    )
]
METHOD DESCRIPTION
aget_by_ids

Async get documents by their IDs.

adelete

Async delete by vector ID or other criteria.

aadd_texts

Async run more texts through the embeddings and add to the VectorStore.

add_documents

Add or update documents in the VectorStore.

aadd_documents

Async run more documents through the embeddings and add to the VectorStore.

search

Return docs most similar to query using a specified search type.

asearch

Async return docs most similar to query using a specified search type.

asimilarity_search_with_score

Async run similarity search with distance.

similarity_search_with_relevance_scores

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

asimilarity_search_with_relevance_scores

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

asimilarity_search

Async return docs most similar to query.

asimilarity_search_by_vector

Async return docs most similar to embedding vector.

amax_marginal_relevance_search

Async return docs selected using the maximal marginal relevance.

amax_marginal_relevance_search_by_vector

Async return docs selected using the maximal marginal relevance.

from_documents

Return VectorStore initialized from documents and embeddings.

afrom_documents

Async return VectorStore initialized from documents and embeddings.

afrom_texts

Async return VectorStore initialized from texts and embeddings.

as_retriever

Return VectorStoreRetriever initialized from this VectorStore.

__init__

Initialize a new instance of QdrantVectorStore.

from_texts

Construct an instance of QdrantVectorStore from a list of texts.

from_existing_collection

Construct QdrantVectorStore from existing collection without adding data.

add_texts

Add texts with embeddings to the VectorStore.

similarity_search

Return docs most similar to query.

similarity_search_with_score

Return docs most similar to query.

similarity_search_with_score_by_vector

Return docs most similar to embedding vector.

similarity_search_by_vector

Return docs most similar to embedding vector.

max_marginal_relevance_search

Return docs selected using the maximal marginal relevance with dense vectors.

max_marginal_relevance_search_by_vector

Return docs selected using the maximal marginal relevance with dense vectors.

max_marginal_relevance_search_with_score_by_vector

Return docs selected using the maximal marginal relevance.

delete

Delete documents by their ids.

get_by_ids

Get documents by their IDs.

client property

client: QdrantClient

Get the Qdrant client instance that is being used.

RETURNS DESCRIPTION
QdrantClient

An instance of QdrantClient.

TYPE: QdrantClient

embeddings property

embeddings: Embeddings | None

Get the dense embeddings instance that is being used.

RETURNS DESCRIPTION
Embeddings

An instance of Embeddings, or None for SPARSE mode.

TYPE: Embeddings | None

sparse_embeddings property

sparse_embeddings: SparseEmbeddings

Get the sparse embeddings instance that is being used.

RAISES DESCRIPTION
ValueError

If sparse embeddings are None.

RETURNS DESCRIPTION
SparseEmbeddings

An instance of SparseEmbeddings.

TYPE: SparseEmbeddings

aget_by_ids async

aget_by_ids(ids: Sequence[str]) -> list[Document]

Async get documents by their IDs.

The returned documents are expected to have the ID field set to the ID of the document in the vector store.

Fewer documents may be returned than requested if some IDs are not found or if there are duplicated IDs.

Users should not assume that the order of the returned documents matches the order of the input IDs. Instead, users should rely on the ID field of the returned documents.

This method should NOT raise exceptions if no documents are found for some IDs.

PARAMETER DESCRIPTION
ids

List of IDs to retrieve.

TYPE: Sequence[str]

RETURNS DESCRIPTION
list[Document]

List of Document objects.

adelete async

adelete(ids: list[str] | None = None, **kwargs: Any) -> bool | None

Async delete by vector ID or other criteria.

PARAMETER DESCRIPTION
ids

List of IDs to delete. If None, delete all.

TYPE: list[str] | None DEFAULT: None

**kwargs

Other keyword arguments that subclasses might use.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
bool | None

True if deletion is successful, False otherwise, None if not implemented.

aadd_texts async

aadd_texts(
    texts: Iterable[str],
    metadatas: list[dict] | None = None,
    *,
    ids: list[str] | None = None,
    **kwargs: Any,
) -> list[str]

Async run more texts through the embeddings and add to the VectorStore.

PARAMETER DESCRIPTION
texts

Iterable of strings to add to the VectorStore.

TYPE: Iterable[str]

metadatas

Optional list of metadatas associated with the texts.

TYPE: list[dict] | None DEFAULT: None

ids

Optional list

TYPE: list[str] | None DEFAULT: None

**kwargs

VectorStore specific parameters.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[str]

List of IDs from adding the texts into the VectorStore.

RAISES DESCRIPTION
ValueError

If the number of metadatas does not match the number of texts.

ValueError

If the number of IDs does not match the number of texts.

add_documents

add_documents(documents: list[Document], **kwargs: Any) -> list[str]

Add or update documents in the VectorStore.

PARAMETER DESCRIPTION
documents

Documents to add to the VectorStore.

TYPE: list[Document]

**kwargs

Additional keyword arguments.

If kwargs contains IDs and documents contain ids, the IDs in the kwargs will receive precedence.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[str]

List of IDs of the added texts.

aadd_documents async

aadd_documents(documents: list[Document], **kwargs: Any) -> list[str]

Async run more documents through the embeddings and add to the VectorStore.

PARAMETER DESCRIPTION
documents

Documents to add to the VectorStore.

TYPE: list[Document]

**kwargs

Additional keyword arguments.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[str]

List of IDs of the added texts.

search

search(query: str, search_type: str, **kwargs: Any) -> list[Document]

Return docs most similar to query using a specified search type.

PARAMETER DESCRIPTION
query

Input text.

TYPE: str

search_type

Type of search to perform. Can be 'similarity', 'mmr', or 'similarity_score_threshold'.

TYPE: str

**kwargs

Arguments to pass to the search method.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[Document]

List of Document objects most similar to the query.

RAISES DESCRIPTION
ValueError

If search_type is not one of 'similarity', 'mmr', or 'similarity_score_threshold'.

asearch async

asearch(query: str, search_type: str, **kwargs: Any) -> list[Document]

Async return docs most similar to query using a specified search type.

PARAMETER DESCRIPTION
query

Input text.

TYPE: str

search_type

Type of search to perform. Can be 'similarity', 'mmr', or 'similarity_score_threshold'.

TYPE: str

**kwargs

Arguments to pass to the search method.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[Document]

List of Document objects most similar to the query.

RAISES DESCRIPTION
ValueError

If search_type is not one of 'similarity', 'mmr', or 'similarity_score_threshold'.

asimilarity_search_with_score async

asimilarity_search_with_score(
    *args: Any, **kwargs: Any
) -> list[tuple[Document, float]]

Async run similarity search with distance.

PARAMETER DESCRIPTION
*args

Arguments to pass to the search method.

TYPE: Any DEFAULT: ()

**kwargs

Arguments to pass to the search method.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[tuple[Document, float]]

List of tuples of (doc, similarity_score).

similarity_search_with_relevance_scores

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.

PARAMETER DESCRIPTION
query

Input text.

TYPE: str

k

Number of Document objects to return.

TYPE: int DEFAULT: 4

**kwargs

kwargs to be passed to similarity search. Should include score_threshold, An optional floating point value between 0 to 1 to filter the resulting set of retrieved docs

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[tuple[Document, float]]

List of tuples of (doc, similarity_score).

asimilarity_search_with_relevance_scores async

asimilarity_search_with_relevance_scores(
    query: str, k: int = 4, **kwargs: Any
) -> list[tuple[Document, float]]

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

0 is dissimilar, 1 is most similar.

PARAMETER DESCRIPTION
query

Input text.

TYPE: str

k

Number of Document objects to return.

TYPE: int DEFAULT: 4

**kwargs

kwargs to be passed to similarity search. Should include score_threshold, An optional floating point value between 0 to 1 to filter the resulting set of retrieved docs

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[tuple[Document, float]]

List of tuples of (doc, similarity_score)

asimilarity_search(query: str, k: int = 4, **kwargs: Any) -> list[Document]

Async return docs most similar to query.

PARAMETER DESCRIPTION
query

Input text.

TYPE: str

k

Number of Document objects to return.

TYPE: int DEFAULT: 4

**kwargs

Arguments to pass to the search method.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[Document]

List of Document objects most similar to the query.

asimilarity_search_by_vector async

asimilarity_search_by_vector(
    embedding: list[float], k: int = 4, **kwargs: Any
) -> list[Document]

Async return docs most similar to embedding vector.

PARAMETER DESCRIPTION
embedding

Embedding to look up documents similar to.

TYPE: list[float]

k

Number of Document objects to return.

TYPE: int DEFAULT: 4

**kwargs

Arguments to pass to the search method.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[Document]

List of Document objects most similar to the query vector.

amax_marginal_relevance_search(
    query: str, k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, **kwargs: Any
) -> list[Document]

Async return docs selected using the maximal marginal relevance.

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

PARAMETER DESCRIPTION
query

Text to look up documents similar to.

TYPE: str

k

Number of Document objects to return.

TYPE: int DEFAULT: 4

fetch_k

Number of Document objects to fetch to pass to MMR algorithm.

TYPE: int DEFAULT: 20

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.

TYPE: float DEFAULT: 0.5

**kwargs

Arguments to pass to the search method.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[Document]

List of Document objects selected by maximal marginal relevance.

amax_marginal_relevance_search_by_vector async

amax_marginal_relevance_search_by_vector(
    embedding: list[float],
    k: int = 4,
    fetch_k: int = 20,
    lambda_mult: float = 0.5,
    **kwargs: Any,
) -> list[Document]

Async return docs selected using the maximal marginal relevance.

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

PARAMETER DESCRIPTION
embedding

Embedding to look up documents similar to.

TYPE: list[float]

k

Number of Document objects to return.

TYPE: int DEFAULT: 4

fetch_k

Number of Document objects to fetch to pass to MMR algorithm.

TYPE: int DEFAULT: 20

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.

TYPE: float DEFAULT: 0.5

**kwargs

Arguments to pass to the search method.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[Document]

List of Document objects selected by maximal marginal relevance.

from_documents classmethod

from_documents(documents: list[Document], embedding: Embeddings, **kwargs: Any) -> Self

Return VectorStore initialized from documents and embeddings.

PARAMETER DESCRIPTION
documents

List of Document objects to add to the VectorStore.

TYPE: list[Document]

embedding

Embedding function to use.

TYPE: Embeddings

**kwargs

Additional keyword arguments.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
Self

VectorStore initialized from documents and embeddings.

afrom_documents async classmethod

afrom_documents(
    documents: list[Document], embedding: Embeddings, **kwargs: Any
) -> Self

Async return VectorStore initialized from documents and embeddings.

PARAMETER DESCRIPTION
documents

List of Document objects to add to the VectorStore.

TYPE: list[Document]

embedding

Embedding function to use.

TYPE: Embeddings

**kwargs

Additional keyword arguments.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
Self

VectorStore initialized from documents and embeddings.

afrom_texts async classmethod

afrom_texts(
    texts: list[str],
    embedding: Embeddings,
    metadatas: list[dict] | None = None,
    *,
    ids: list[str] | None = None,
    **kwargs: Any,
) -> Self

Async return VectorStore initialized from texts and embeddings.

PARAMETER DESCRIPTION
texts

Texts to add to the VectorStore.

TYPE: list[str]

embedding

Embedding function to use.

TYPE: Embeddings

metadatas

Optional list of metadatas associated with the texts.

TYPE: list[dict] | None DEFAULT: None

ids

Optional list of IDs associated with the texts.

TYPE: list[str] | None DEFAULT: None

**kwargs

Additional keyword arguments.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
Self

VectorStore initialized from texts and embeddings.

as_retriever

as_retriever(**kwargs: Any) -> VectorStoreRetriever

Return VectorStoreRetriever initialized from this VectorStore.

PARAMETER DESCRIPTION
**kwargs

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

  • search_type: Defines the type of search that the Retriever should perform. Can be 'similarity' (default), 'mmr', or 'similarity_score_threshold'.
  • search_kwargs: 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

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
VectorStoreRetriever

Retriever class for VectorStore.

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"}}
)

__init__

__init__(
    client: QdrantClient,
    collection_name: str,
    embedding: Embeddings | None = None,
    retrieval_mode: RetrievalMode = DENSE,
    vector_name: str = VECTOR_NAME,
    content_payload_key: str = CONTENT_KEY,
    metadata_payload_key: str = METADATA_KEY,
    distance: Distance = COSINE,
    sparse_embedding: SparseEmbeddings | None = None,
    sparse_vector_name: str = SPARSE_VECTOR_NAME,
    validate_embeddings: bool = True,
    validate_collection_config: bool = True,
) -> None

Initialize a new instance of QdrantVectorStore.

qdrant = Qdrant(
    client=client,
    collection_name="my-collection",
    embedding=OpenAIEmbeddings(),
    retrieval_mode=RetrievalMode.HYBRID,
    sparse_embedding=FastEmbedSparse(),
)

from_texts classmethod

from_texts(
    texts: list[str],
    embedding: Embeddings | None = None,
    metadatas: list[dict] | None = None,
    ids: Sequence[str | int] | None = None,
    collection_name: str | None = None,
    location: str | None = None,
    url: str | None = None,
    port: int | None = 6333,
    grpc_port: int = 6334,
    prefer_grpc: bool = False,
    https: bool | None = None,
    api_key: str | None = None,
    prefix: str | None = None,
    timeout: int | None = None,
    host: str | None = None,
    path: str | None = None,
    distance: Distance = COSINE,
    content_payload_key: str = CONTENT_KEY,
    metadata_payload_key: str = METADATA_KEY,
    vector_name: str = VECTOR_NAME,
    retrieval_mode: RetrievalMode = DENSE,
    sparse_embedding: SparseEmbeddings | None = None,
    sparse_vector_name: str = SPARSE_VECTOR_NAME,
    collection_create_options: dict[str, Any] | None = None,
    vector_params: dict[str, Any] | None = None,
    sparse_vector_params: dict[str, Any] | None = None,
    batch_size: int = 64,
    force_recreate: bool = False,
    validate_embeddings: bool = True,
    validate_collection_config: bool = True,
    **kwargs: Any,
) -> QdrantVectorStore

Construct an instance of QdrantVectorStore from a list of texts.

This is a user-friendly interface that:

  1. Creates embeddings, one for each text
  2. Creates a Qdrant collection if it doesn't exist.
  3. Adds the text embeddings to the Qdrant database

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

from langchain_qdrant import Qdrant
from langchain_openai import OpenAIEmbeddings

embeddings = OpenAIEmbeddings()
qdrant = Qdrant.from_texts(texts, embeddings, url="http://localhost:6333")

from_existing_collection classmethod

from_existing_collection(
    collection_name: str,
    embedding: Embeddings | None = None,
    retrieval_mode: RetrievalMode = DENSE,
    location: str | None = None,
    url: str | None = None,
    port: int | None = 6333,
    grpc_port: int = 6334,
    prefer_grpc: bool = False,
    https: bool | None = None,
    api_key: str | None = None,
    prefix: str | None = None,
    timeout: int | None = None,
    host: str | None = None,
    path: str | None = None,
    distance: Distance = COSINE,
    content_payload_key: str = CONTENT_KEY,
    metadata_payload_key: str = METADATA_KEY,
    vector_name: str = VECTOR_NAME,
    sparse_vector_name: str = SPARSE_VECTOR_NAME,
    sparse_embedding: SparseEmbeddings | None = None,
    validate_embeddings: bool = True,
    validate_collection_config: bool = True,
    **kwargs: Any,
) -> QdrantVectorStore

Construct QdrantVectorStore from existing collection without adding data.

RETURNS DESCRIPTION
QdrantVectorStore

A new instance of QdrantVectorStore.

TYPE: QdrantVectorStore

add_texts

add_texts(
    texts: Iterable[str],
    metadatas: list[dict] | None = None,
    ids: Sequence[str | int] | None = None,
    batch_size: int = 64,
    **kwargs: Any,
) -> list[str | int]

Add texts with embeddings to the VectorStore.

RETURNS DESCRIPTION
list[str | int]

List of ids from adding the texts into the VectorStore.

similarity_search(
    query: str,
    k: int = 4,
    filter: Filter | None = None,
    search_params: SearchParams | None = None,
    offset: int = 0,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    hybrid_fusion: FusionQuery | None = None,
    **kwargs: Any,
) -> list[Document]

Return docs most similar to query.

RETURNS DESCRIPTION
list[Document]

List of Document objects most similar to the query.

similarity_search_with_score

similarity_search_with_score(
    query: str,
    k: int = 4,
    filter: Filter | None = None,
    search_params: SearchParams | None = None,
    offset: int = 0,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    hybrid_fusion: FusionQuery | None = None,
    **kwargs: Any,
) -> list[tuple[Document, float]]

Return docs most similar to query.

RETURNS DESCRIPTION
list[tuple[Document, float]]

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

similarity_search_with_score_by_vector

similarity_search_with_score_by_vector(
    embedding: list[float],
    k: int = 4,
    filter: Filter | None = None,
    search_params: SearchParams | None = None,
    offset: int = 0,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    **kwargs: Any,
) -> list[tuple[Document, float]]

Return docs most similar to embedding vector.

RETURNS DESCRIPTION
list[tuple[Document, float]]

List of Document objects most similar to the query and distance for each.

similarity_search_by_vector

similarity_search_by_vector(
    embedding: list[float],
    k: int = 4,
    filter: Filter | None = None,
    search_params: SearchParams | None = None,
    offset: int = 0,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    **kwargs: Any,
) -> list[Document]

Return docs most similar to embedding vector.

RETURNS DESCRIPTION
list[Document]

List of Document objects most similar to the query.

max_marginal_relevance_search(
    query: str,
    k: int = 4,
    fetch_k: int = 20,
    lambda_mult: float = 0.5,
    filter: Filter | None = None,
    search_params: SearchParams | None = None,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    **kwargs: Any,
) -> list[Document]

Return docs selected using the maximal marginal relevance with dense vectors.

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

RETURNS DESCRIPTION
list[Document]

List of Document objects selected by maximal marginal relevance.

max_marginal_relevance_search_by_vector

max_marginal_relevance_search_by_vector(
    embedding: list[float],
    k: int = 4,
    fetch_k: int = 20,
    lambda_mult: float = 0.5,
    filter: Filter | None = None,
    search_params: SearchParams | None = None,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    **kwargs: Any,
) -> list[Document]

Return docs selected using the maximal marginal relevance with dense vectors.

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

RETURNS DESCRIPTION
list[Document]

List of Document objects selected by maximal marginal relevance.

max_marginal_relevance_search_with_score_by_vector

max_marginal_relevance_search_with_score_by_vector(
    embedding: list[float],
    k: int = 4,
    fetch_k: int = 20,
    lambda_mult: float = 0.5,
    filter: Filter | None = None,
    search_params: SearchParams | None = None,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    **kwargs: Any,
) -> list[tuple[Document, float]]

Return docs selected using the maximal marginal relevance.

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

RETURNS DESCRIPTION
list[tuple[Document, float]]

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

delete

delete(ids: list[str | int] | None = None, **kwargs: Any) -> bool | None

Delete documents by their ids.

PARAMETER DESCRIPTION
ids

List of ids to delete.

TYPE: list[str | int] | None DEFAULT: None

**kwargs

Other keyword arguments that subclasses might use.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
bool | None

True if deletion is successful, False otherwise.

get_by_ids

get_by_ids(ids: Sequence[str | int]) -> list[Document]

Get documents by their IDs.

The returned documents are expected to have the ID field set to the ID of the document in the vector store.

Fewer documents may be returned than requested if some IDs are not found or if there are duplicated IDs.

Users should not assume that the order of the returned documents matches the order of the input IDs. Instead, users should rely on the ID field of the returned documents.

This method should NOT raise exceptions if no documents are found for some IDs.

PARAMETER DESCRIPTION
ids

List of IDs to retrieve.

TYPE: Sequence[str]

RETURNS DESCRIPTION
list[Document]

List of Document objects.

RetrievalMode

Bases: str, Enum

Modes for retrieving vectors from Qdrant.

SparseEmbeddings

Bases: ABC

An interface for sparse embedding models to use with Qdrant.

METHOD DESCRIPTION
embed_documents

Embed search docs.

embed_query

Embed query text.

aembed_documents

Asynchronous Embed search docs.

aembed_query

Asynchronous Embed query text.

embed_documents abstractmethod

embed_documents(texts: list[str]) -> list[SparseVector]

Embed search docs.

embed_query abstractmethod

embed_query(text: str) -> SparseVector

Embed query text.

aembed_documents async

aembed_documents(texts: list[str]) -> list[SparseVector]

Asynchronous Embed search docs.

aembed_query async

aembed_query(text: str) -> SparseVector

Asynchronous Embed query text.

SparseVector

Bases: BaseModel

Sparse vector structure.

Qdrant

Bases: VectorStore

Qdrant vector store.

from qdrant_client import QdrantClient
from langchain_qdrant import Qdrant

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

Get documents by their IDs.

aget_by_ids

Async get documents by their IDs.

add_documents

Add or update documents in the VectorStore.

aadd_documents

Async run more documents through the embeddings and add to the VectorStore.

search

Return docs most similar to query using a specified search type.

asearch

Async return docs most similar to query using a specified search type.

similarity_search_with_relevance_scores

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

asimilarity_search_with_relevance_scores

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

from_documents

Return VectorStore initialized from documents and embeddings.

afrom_documents

Async return VectorStore initialized from documents and embeddings.

as_retriever

Return VectorStoreRetriever initialized from this VectorStore.

__init__

Initialize with necessary components.

add_texts

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

aadd_texts

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

similarity_search

Return docs most similar to query.

asimilarity_search

Return docs most similar to query.

similarity_search_with_score

Return docs most similar to query.

asimilarity_search_with_score

Return docs most similar to query.

similarity_search_by_vector

Return docs most similar to embedding vector.

asimilarity_search_by_vector

Return docs most similar to embedding vector.

similarity_search_with_score_by_vector

Return docs most similar to embedding vector.

asimilarity_search_with_score_by_vector

Return docs most similar to embedding vector.

max_marginal_relevance_search

Return docs selected using the maximal marginal relevance.

amax_marginal_relevance_search

Return docs selected using the maximal marginal relevance.

max_marginal_relevance_search_by_vector

Return docs selected using the maximal marginal relevance.

amax_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.

amax_marginal_relevance_search_with_score_by_vector

Return docs selected using the maximal marginal relevance.

delete

Delete by vector ID or other criteria.

adelete

Delete by vector ID or other criteria.

from_texts

Construct Qdrant wrapper from a list of texts.

from_existing_collection

Get instance of an existing Qdrant collection.

afrom_texts

Construct Qdrant wrapper from a list of texts.

embeddings property

embeddings: Embeddings | None

Access the query embedding object if available.

get_by_ids

get_by_ids(ids: Sequence[str]) -> list[Document]

Get documents by their IDs.

The returned documents are expected to have the ID field set to the ID of the document in the vector store.

Fewer documents may be returned than requested if some IDs are not found or if there are duplicated IDs.

Users should not assume that the order of the returned documents matches the order of the input IDs. Instead, users should rely on the ID field of the returned documents.

This method should NOT raise exceptions if no documents are found for some IDs.

PARAMETER DESCRIPTION
ids

List of IDs to retrieve.

TYPE: Sequence[str]

RETURNS DESCRIPTION
list[Document]

List of Document objects.

aget_by_ids async

aget_by_ids(ids: Sequence[str]) -> list[Document]

Async get documents by their IDs.

The returned documents are expected to have the ID field set to the ID of the document in the vector store.

Fewer documents may be returned than requested if some IDs are not found or if there are duplicated IDs.

Users should not assume that the order of the returned documents matches the order of the input IDs. Instead, users should rely on the ID field of the returned documents.

This method should NOT raise exceptions if no documents are found for some IDs.

PARAMETER DESCRIPTION
ids

List of IDs to retrieve.

TYPE: Sequence[str]

RETURNS DESCRIPTION
list[Document]

List of Document objects.

add_documents

add_documents(documents: list[Document], **kwargs: Any) -> list[str]

Add or update documents in the VectorStore.

PARAMETER DESCRIPTION
documents

Documents to add to the VectorStore.

TYPE: list[Document]

**kwargs

Additional keyword arguments.

If kwargs contains IDs and documents contain ids, the IDs in the kwargs will receive precedence.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[str]

List of IDs of the added texts.

aadd_documents async

aadd_documents(documents: list[Document], **kwargs: Any) -> list[str]

Async run more documents through the embeddings and add to the VectorStore.

PARAMETER DESCRIPTION
documents

Documents to add to the VectorStore.

TYPE: list[Document]

**kwargs

Additional keyword arguments.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[str]

List of IDs of the added texts.

search

search(query: str, search_type: str, **kwargs: Any) -> list[Document]

Return docs most similar to query using a specified search type.

PARAMETER DESCRIPTION
query

Input text.

TYPE: str

search_type

Type of search to perform. Can be 'similarity', 'mmr', or 'similarity_score_threshold'.

TYPE: str

**kwargs

Arguments to pass to the search method.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[Document]

List of Document objects most similar to the query.

RAISES DESCRIPTION
ValueError

If search_type is not one of 'similarity', 'mmr', or 'similarity_score_threshold'.

asearch async

asearch(query: str, search_type: str, **kwargs: Any) -> list[Document]

Async return docs most similar to query using a specified search type.

PARAMETER DESCRIPTION
query

Input text.

TYPE: str

search_type

Type of search to perform. Can be 'similarity', 'mmr', or 'similarity_score_threshold'.

TYPE: str

**kwargs

Arguments to pass to the search method.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[Document]

List of Document objects most similar to the query.

RAISES DESCRIPTION
ValueError

If search_type is not one of 'similarity', 'mmr', or 'similarity_score_threshold'.

similarity_search_with_relevance_scores

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.

PARAMETER DESCRIPTION
query

Input text.

TYPE: str

k

Number of Document objects to return.

TYPE: int DEFAULT: 4

**kwargs

kwargs to be passed to similarity search. Should include score_threshold, An optional floating point value between 0 to 1 to filter the resulting set of retrieved docs

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[tuple[Document, float]]

List of tuples of (doc, similarity_score).

asimilarity_search_with_relevance_scores async

asimilarity_search_with_relevance_scores(
    query: str, k: int = 4, **kwargs: Any
) -> list[tuple[Document, float]]

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

0 is dissimilar, 1 is most similar.

PARAMETER DESCRIPTION
query

Input text.

TYPE: str

k

Number of Document objects to return.

TYPE: int DEFAULT: 4

**kwargs

kwargs to be passed to similarity search. Should include score_threshold, An optional floating point value between 0 to 1 to filter the resulting set of retrieved docs

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[tuple[Document, float]]

List of tuples of (doc, similarity_score)

from_documents classmethod

from_documents(documents: list[Document], embedding: Embeddings, **kwargs: Any) -> Self

Return VectorStore initialized from documents and embeddings.

PARAMETER DESCRIPTION
documents

List of Document objects to add to the VectorStore.

TYPE: list[Document]

embedding

Embedding function to use.

TYPE: Embeddings

**kwargs

Additional keyword arguments.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
Self

VectorStore initialized from documents and embeddings.

afrom_documents async classmethod

afrom_documents(
    documents: list[Document], embedding: Embeddings, **kwargs: Any
) -> Self

Async return VectorStore initialized from documents and embeddings.

PARAMETER DESCRIPTION
documents

List of Document objects to add to the VectorStore.

TYPE: list[Document]

embedding

Embedding function to use.

TYPE: Embeddings

**kwargs

Additional keyword arguments.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
Self

VectorStore initialized from documents and embeddings.

as_retriever

as_retriever(**kwargs: Any) -> VectorStoreRetriever

Return VectorStoreRetriever initialized from this VectorStore.

PARAMETER DESCRIPTION
**kwargs

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

  • search_type: Defines the type of search that the Retriever should perform. Can be 'similarity' (default), 'mmr', or 'similarity_score_threshold'.
  • search_kwargs: 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

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
VectorStoreRetriever

Retriever class for VectorStore.

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"}}
)

__init__

__init__(
    client: Any,
    collection_name: str,
    embeddings: Embeddings | None = None,
    content_payload_key: str = CONTENT_KEY,
    metadata_payload_key: str = METADATA_KEY,
    distance_strategy: str = "COSINE",
    vector_name: str | None = VECTOR_NAME,
    async_client: Any | None = None,
    embedding_function: Callable | None = None,
) -> None

Initialize with necessary components.

add_texts

add_texts(
    texts: Iterable[str],
    metadatas: list[dict] | None = None,
    ids: Sequence[str] | None = None,
    batch_size: int = 64,
    **kwargs: Any,
) -> list[str]

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

PARAMETER DESCRIPTION
texts

Iterable of strings to add to the VectorStore.

TYPE: Iterable[str]

metadatas

Optional list of metadatas associated with the texts.

TYPE: list[dict] | None DEFAULT: None

ids

Optional list of ids to associate with the texts. Ids have to be uuid-like strings.

TYPE: Sequence[str] | None DEFAULT: None

batch_size

How many vectors upload per-request. Default: 64

TYPE: int DEFAULT: 64

**kwargs

Additional keyword arguments.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[str]

List of ids from adding the texts into the VectorStore.

aadd_texts async

aadd_texts(
    texts: Iterable[str],
    metadatas: list[dict] | None = None,
    ids: Sequence[str] | None = None,
    batch_size: int = 64,
    **kwargs: Any,
) -> list[str]

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

PARAMETER DESCRIPTION
texts

Iterable of strings to add to the VectorStore.

TYPE: Iterable[str]

metadatas

Optional list of metadatas associated with the texts.

TYPE: list[dict] | None DEFAULT: None

ids

Optional list of ids to associate with the texts. Ids have to be uuid-like strings.

TYPE: Sequence[str] | None DEFAULT: None

batch_size

How many vectors upload per-request. Default: 64

TYPE: int DEFAULT: 64

**kwargs

Additional keyword arguments.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[str]

List of ids from adding the texts into the VectorStore.

similarity_search(
    query: str,
    k: int = 4,
    filter: MetadataFilter | None = None,
    search_params: SearchParams | None = None,
    offset: int = 0,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    **kwargs: Any,
) -> list[Document]

Return docs most similar to query.

PARAMETER DESCRIPTION
query

Text to look up documents similar to.

TYPE: str

k

Number of Documents to return.

TYPE: int DEFAULT: 4

filter

Filter by metadata.

TYPE: MetadataFilter | None DEFAULT: None

search_params

Additional search params

TYPE: SearchParams | None DEFAULT: None

offset

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

TYPE: int DEFAULT: 0

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.

TYPE: float | None DEFAULT: None

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

TYPE: ReadConsistency | None DEFAULT: None

**kwargs

Any other named arguments to pass through to QdrantClient.search()

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[Document]

List of Document objects most similar to the query.

asimilarity_search(
    query: str, k: int = 4, filter: MetadataFilter | None = None, **kwargs: Any
) -> list[Document]

Return docs most similar to query.

PARAMETER DESCRIPTION
query

Text to look up documents similar to.

TYPE: str

k

Number of Documents to return.

TYPE: int DEFAULT: 4

filter

Filter by metadata.

TYPE: MetadataFilter | None DEFAULT: None

**kwargs

Additional keyword arguments.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[Document]

List of Document objects most similar to the query.

similarity_search_with_score

similarity_search_with_score(
    query: str,
    k: int = 4,
    filter: MetadataFilter | None = None,
    search_params: SearchParams | None = None,
    offset: int = 0,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    **kwargs: Any,
) -> list[tuple[Document, float]]

Return docs most similar to query.

PARAMETER DESCRIPTION
query

Text to look up documents similar to.

TYPE: str

k

Number of Documents to return.

TYPE: int DEFAULT: 4

filter

Filter by metadata.

TYPE: MetadataFilter | None DEFAULT: None

search_params

Additional search params

TYPE: SearchParams | None DEFAULT: None

offset

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

TYPE: int DEFAULT: 0

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.

TYPE: float | None DEFAULT: None

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

TYPE: ReadConsistency | None DEFAULT: None

**kwargs

Any other named arguments to pass through to QdrantClient.search()

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[tuple[Document, float]]

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

asimilarity_search_with_score async

asimilarity_search_with_score(
    query: str,
    k: int = 4,
    filter: MetadataFilter | None = None,
    search_params: SearchParams | None = None,
    offset: int = 0,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    **kwargs: Any,
) -> list[tuple[Document, float]]

Return docs most similar to query.

PARAMETER DESCRIPTION
query

Text to look up documents similar to.

TYPE: str

k

Number of Documents to return.

TYPE: int DEFAULT: 4

filter

Filter by metadata.

TYPE: MetadataFilter | None DEFAULT: None

search_params

Additional search params

TYPE: SearchParams | None DEFAULT: None

offset

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

TYPE: int DEFAULT: 0

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.

TYPE: float | None DEFAULT: None

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

TYPE: ReadConsistency | None DEFAULT: None

**kwargs

Any other named arguments to pass through to AsyncQdrantClient.Search().

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[tuple[Document, float]]

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

similarity_search_by_vector

similarity_search_by_vector(
    embedding: list[float],
    k: int = 4,
    filter: MetadataFilter | None = None,
    search_params: SearchParams | None = None,
    offset: int = 0,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    **kwargs: Any,
) -> list[Document]

Return docs most similar to embedding vector.

PARAMETER DESCRIPTION
embedding

Embedding vector to look up documents similar to.

TYPE: list[float]

k

Number of Documents to return.

TYPE: int DEFAULT: 4

filter

Filter by metadata.

TYPE: MetadataFilter | None DEFAULT: None

search_params

Additional search params

TYPE: SearchParams | None DEFAULT: None

offset

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

TYPE: int DEFAULT: 0

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.

TYPE: float | None DEFAULT: None

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

TYPE: ReadConsistency | None DEFAULT: None

**kwargs

Any other named arguments to pass through to QdrantClient.search()

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[Document]

List of Document objects most similar to the query.

asimilarity_search_by_vector async

asimilarity_search_by_vector(
    embedding: list[float],
    k: int = 4,
    filter: MetadataFilter | None = None,
    search_params: SearchParams | None = None,
    offset: int = 0,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    **kwargs: Any,
) -> list[Document]

Return docs most similar to embedding vector.

PARAMETER DESCRIPTION
embedding

Embedding vector to look up documents similar to.

TYPE: list[float]

k

Number of Documents to return.

TYPE: int DEFAULT: 4

filter

Filter by metadata.

TYPE: MetadataFilter | None DEFAULT: None

search_params

Additional search params

TYPE: SearchParams | None DEFAULT: None

offset

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

TYPE: int DEFAULT: 0

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.

TYPE: float | None DEFAULT: None

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

TYPE: ReadConsistency | None DEFAULT: None

**kwargs

Any other named arguments to pass through to AsyncQdrantClient.Search().

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[Document]

List of Document objects most similar to the query.

similarity_search_with_score_by_vector

similarity_search_with_score_by_vector(
    embedding: list[float],
    k: int = 4,
    filter: MetadataFilter | None = None,
    search_params: SearchParams | None = None,
    offset: int = 0,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    **kwargs: Any,
) -> list[tuple[Document, float]]

Return docs most similar to embedding vector.

PARAMETER DESCRIPTION
embedding

Embedding vector to look up documents similar to.

TYPE: list[float]

k

Number of Documents to return.

TYPE: int DEFAULT: 4

filter

Filter by metadata.

TYPE: MetadataFilter | None DEFAULT: None

search_params

Additional search params

TYPE: SearchParams | None DEFAULT: None

offset

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

TYPE: int DEFAULT: 0

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.

TYPE: float | None DEFAULT: None

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

TYPE: ReadConsistency | None DEFAULT: None

**kwargs

Any other named arguments to pass through to QdrantClient.search()

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[tuple[Document, float]]

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

asimilarity_search_with_score_by_vector async

asimilarity_search_with_score_by_vector(
    embedding: list[float],
    k: int = 4,
    filter: MetadataFilter | None = None,
    search_params: SearchParams | None = None,
    offset: int = 0,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    **kwargs: Any,
) -> list[tuple[Document, float]]

Return docs most similar to embedding vector.

PARAMETER DESCRIPTION
embedding

Embedding vector to look up documents similar to.

TYPE: list[float]

k

Number of Documents to return.

TYPE: int DEFAULT: 4

filter

Filter by metadata.

TYPE: MetadataFilter | None DEFAULT: None

search_params

Additional search params

TYPE: SearchParams | None DEFAULT: None

offset

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

TYPE: int DEFAULT: 0

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.

TYPE: float | None DEFAULT: None

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

TYPE: ReadConsistency | None DEFAULT: None

**kwargs

Any other named arguments to pass through to AsyncQdrantClient.Search().

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[tuple[Document, float]]

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

max_marginal_relevance_search(
    query: str,
    k: int = 4,
    fetch_k: int = 20,
    lambda_mult: float = 0.5,
    filter: MetadataFilter | None = None,
    search_params: SearchParams | None = None,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    **kwargs: Any,
) -> list[Document]

Return docs selected using the maximal marginal relevance.

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

PARAMETER DESCRIPTION
query

Text to look up documents similar to.

TYPE: str

k

Number of Documents to return.

TYPE: int DEFAULT: 4

fetch_k

Number of Documents to fetch to pass to MMR algorithm.

TYPE: int DEFAULT: 20

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.

TYPE: float DEFAULT: 0.5

filter

Filter by metadata.

TYPE: MetadataFilter | None DEFAULT: None

search_params

Additional search params

TYPE: SearchParams | None DEFAULT: None

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.

TYPE: float | None DEFAULT: None

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

TYPE: ReadConsistency | None DEFAULT: None

**kwargs

Any other named arguments to pass through to QdrantClient.search()

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[Document]

List of Document objects selected by maximal marginal relevance.

amax_marginal_relevance_search(
    query: str,
    k: int = 4,
    fetch_k: int = 20,
    lambda_mult: float = 0.5,
    filter: MetadataFilter | None = None,
    search_params: SearchParams | None = None,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    **kwargs: Any,
) -> list[Document]

Return docs selected using the maximal marginal relevance.

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

PARAMETER DESCRIPTION
query

Text to look up documents similar to.

TYPE: str

k

Number of Documents to return.

TYPE: int DEFAULT: 4

fetch_k

Number of Documents to fetch to pass to MMR algorithm.

TYPE: int DEFAULT: 20

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.

TYPE: float DEFAULT: 0.5

filter

Filter by metadata.

TYPE: MetadataFilter | None DEFAULT: None

search_params

Additional search params

TYPE: SearchParams | None DEFAULT: None

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.

TYPE: float | None DEFAULT: None

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

TYPE: ReadConsistency | None DEFAULT: None

**kwargs

Any other named arguments to pass through to AsyncQdrantClient.Search().

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[Document]

List of Document objects selected by maximal marginal relevance.

max_marginal_relevance_search_by_vector

max_marginal_relevance_search_by_vector(
    embedding: list[float],
    k: int = 4,
    fetch_k: int = 20,
    lambda_mult: float = 0.5,
    filter: MetadataFilter | None = None,
    search_params: SearchParams | None = None,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    **kwargs: Any,
) -> list[Document]

Return docs selected using the maximal marginal relevance.

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

PARAMETER DESCRIPTION
embedding

Embedding to look up documents similar to.

TYPE: list[float]

k

Number of Documents to return.

TYPE: int DEFAULT: 4

fetch_k

Number of Documents to fetch to pass to MMR algorithm.

TYPE: int DEFAULT: 20

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.

TYPE: float DEFAULT: 0.5

filter

Filter by metadata.

TYPE: MetadataFilter | None DEFAULT: None

search_params

Additional search params

TYPE: SearchParams | None DEFAULT: None

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.

TYPE: float | None DEFAULT: None

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

TYPE: ReadConsistency | None DEFAULT: None

**kwargs

Any other named arguments to pass through to QdrantClient.search()

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[Document]

List of Document objects selected by maximal marginal relevance.

amax_marginal_relevance_search_by_vector async

amax_marginal_relevance_search_by_vector(
    embedding: list[float],
    k: int = 4,
    fetch_k: int = 20,
    lambda_mult: float = 0.5,
    filter: MetadataFilter | None = None,
    search_params: SearchParams | None = None,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    **kwargs: Any,
) -> list[Document]

Return docs selected using the maximal marginal relevance.

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

PARAMETER DESCRIPTION
embedding

Embedding vector to look up documents similar to.

TYPE: list[float]

k

Number of Document objects to return.

TYPE: int DEFAULT: 4

fetch_k

Number of Document to fetch to pass to MMR algorithm.

TYPE: int DEFAULT: 20

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.

TYPE: float DEFAULT: 0.5

filter

Filter by metadata.

TYPE: MetadataFilter | None DEFAULT: None

search_params

Additional search params

TYPE: SearchParams | None DEFAULT: None

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.

TYPE: float | None DEFAULT: None

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

TYPE: ReadConsistency | None DEFAULT: None

**kwargs

Any other named arguments to pass through to AsyncQdrantClient.Search().

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[Document]

List of Document objects selected by maximal marginal relevance and

list[Document]

distance for each.

max_marginal_relevance_search_with_score_by_vector

max_marginal_relevance_search_with_score_by_vector(
    embedding: list[float],
    k: int = 4,
    fetch_k: int = 20,
    lambda_mult: float = 0.5,
    filter: MetadataFilter | None = None,
    search_params: SearchParams | None = None,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    **kwargs: Any,
) -> list[tuple[Document, float]]

Return docs selected using the maximal marginal relevance.

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

PARAMETER DESCRIPTION
embedding

Embedding vector to look up documents similar to.

TYPE: list[float]

k

Number of Documents to return.

TYPE: int DEFAULT: 4

fetch_k

Number of Documents to fetch to pass to MMR algorithm.

TYPE: int DEFAULT: 20

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.

TYPE: float DEFAULT: 0.5

filter

Filter by metadata.

TYPE: MetadataFilter | None DEFAULT: None

search_params

Additional search params

TYPE: SearchParams | None DEFAULT: None

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.

TYPE: float | None DEFAULT: None

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

TYPE: ReadConsistency | None DEFAULT: None

**kwargs

Any other named arguments to pass through to QdrantClient.search()

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[tuple[Document, float]]

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

amax_marginal_relevance_search_with_score_by_vector 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: MetadataFilter | None = None,
    search_params: SearchParams | None = None,
    score_threshold: float | None = None,
    consistency: ReadConsistency | None = None,
    **kwargs: Any,
) -> list[tuple[Document, float]]

Return docs selected using the maximal marginal relevance.

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

PARAMETER DESCRIPTION
embedding

Embedding vector to look up documents similar to.

TYPE: list[float]

k

Number of Documents to return.

TYPE: int DEFAULT: 4

fetch_k

Number of Documents to fetch to pass to MMR algorithm.

TYPE: int DEFAULT: 20

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.

TYPE: float DEFAULT: 0.5

filter

Filter by metadata.

TYPE: MetadataFilter | None DEFAULT: None

search_params

Additional search params.

TYPE: SearchParams | None DEFAULT: None

score_threshold

Define a minimal score threshold for the result.

TYPE: float | None DEFAULT: None

consistency

Read consistency of the search.

TYPE: ReadConsistency | None DEFAULT: None

**kwargs

Additional keyword arguments.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
list[tuple[Document, float]]

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

delete

delete(ids: list[str] | None = None, **kwargs: Any) -> bool | None

Delete by vector ID or other criteria.

PARAMETER DESCRIPTION
ids

List of ids to delete.

TYPE: list[str] | None DEFAULT: None

**kwargs

Other keyword arguments that subclasses might use.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
bool | None

True if deletion is successful, False otherwise.

adelete async

adelete(ids: list[str] | None = None, **kwargs: Any) -> bool | None

Delete by vector ID or other criteria.

PARAMETER DESCRIPTION
ids

List of ids to delete.

TYPE: list[str] | None DEFAULT: None

**kwargs

Other keyword arguments that subclasses might use.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
bool | None

True if deletion is successful, False otherwise.

from_texts classmethod

from_texts(
    texts: list[str],
    embedding: Embeddings,
    metadatas: list[dict] | None = None,
    ids: Sequence[str] | None = None,
    location: str | None = None,
    url: str | None = None,
    port: int | None = 6333,
    grpc_port: int = 6334,
    prefer_grpc: bool = False,
    https: bool | None = None,
    api_key: str | None = None,
    prefix: str | None = None,
    timeout: int | None = None,
    host: str | None = None,
    path: str | None = None,
    collection_name: str | None = None,
    distance_func: str = "Cosine",
    content_payload_key: str = CONTENT_KEY,
    metadata_payload_key: str = METADATA_KEY,
    vector_name: str | None = VECTOR_NAME,
    batch_size: int = 64,
    shard_number: int | None = None,
    replication_factor: int | None = None,
    write_consistency_factor: int | None = None,
    on_disk_payload: bool | None = None,
    hnsw_config: HnswConfigDiff | None = None,
    optimizers_config: OptimizersConfigDiff | None = None,
    wal_config: WalConfigDiff | None = None,
    quantization_config: QuantizationConfig | None = None,
    init_from: InitFrom | None = None,
    on_disk: bool | None = None,
    force_recreate: bool = False,
    **kwargs: Any,
) -> Qdrant

Construct Qdrant wrapper from a list of texts.

PARAMETER DESCRIPTION
texts

A list of texts to be indexed in Qdrant.

TYPE: list[str]

embedding

A subclass of Embeddings, responsible for text vectorization.

TYPE: Embeddings

metadatas

An optional list of metadata. If provided it has to be of the same length as a list of texts.

TYPE: list[dict] | None DEFAULT: None

ids

Optional list of ids to associate with the texts. Ids have to be uuid-like strings.

TYPE: Sequence[str] | None DEFAULT: None

location

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.

TYPE: str | None DEFAULT: None

url

either host or str of "scheme | None, host, port | None, prefix | None".

TYPE: str | None DEFAULT: None

port

Port of the REST API interface. Default: 6333

TYPE: int | None DEFAULT: 6333

grpc_port

Port of the gRPC interface. Default: 6334

TYPE: int DEFAULT: 6334

prefer_grpc

If true - use gPRC interface whenever possible in custom methods. Default: False

TYPE: bool DEFAULT: False

https

If true - use HTTPS(SSL) protocol. Default: None

TYPE: bool | None DEFAULT: None

api_key
API key for authentication in Qdrant Cloud. Default: None
Can also be set via environment variable `QDRANT_API_KEY`.

TYPE: str | None DEFAULT: None

prefix

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

TYPE: str | None DEFAULT: None

timeout

Timeout for REST and gRPC API requests. Default: 5.0 seconds for REST and unlimited for gRPC

TYPE: int | None DEFAULT: None

host

Host name of Qdrant service. If url and host are None, set to 'localhost'. Default: None

TYPE: str | None DEFAULT: None

path

Path in which the vectors will be stored while using local mode. Default: None

TYPE: str | None DEFAULT: None

collection_name

Name of the Qdrant collection to be used. If not provided, it will be created randomly. Default: None

TYPE: str | None DEFAULT: None

distance_func

Distance function. One of: "Cosine" / "Euclid" / "Dot". Default: "Cosine"

TYPE: str DEFAULT: 'Cosine'

content_payload_key

A payload key used to store the content of the document. Default: "page_content"

TYPE: str DEFAULT: CONTENT_KEY

metadata_payload_key

A payload key used to store the metadata of the document. Default: "metadata"

TYPE: str DEFAULT: METADATA_KEY

vector_name

Name of the vector to be used internally in Qdrant. Default: None

TYPE: str | None DEFAULT: VECTOR_NAME

batch_size

How many vectors upload per-request. Default: 64

TYPE: int DEFAULT: 64

shard_number

Number of shards in collection. Default is 1, minimum is 1.

TYPE: int | None DEFAULT: None

replication_factor

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.

TYPE: int | None DEFAULT: None

write_consistency_factor

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.

TYPE: int | None DEFAULT: None

on_disk_payload

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.

TYPE: bool | None DEFAULT: None

hnsw_config

Params for HNSW index

TYPE: HnswConfigDiff | None DEFAULT: None

optimizers_config

Params for optimizer

TYPE: OptimizersConfigDiff | None DEFAULT: None

wal_config

Params for Write-Ahead-Log

TYPE: WalConfigDiff | None DEFAULT: None

quantization_config

Params for quantization, if None - quantization will be disabled

TYPE: QuantizationConfig | None DEFAULT: None

init_from

Use data stored in another collection to initialize this collection

TYPE: InitFrom | None DEFAULT: None

on_disk

If true - vectors will be stored on disk, reducing memory usage.

TYPE: bool | None DEFAULT: None

force_recreate

Force recreating the collection

TYPE: bool DEFAULT: False

**kwargs

Additional arguments passed directly into REST client initialization

TYPE: Any DEFAULT: {}

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)
  3. Adds the text embeddings to the Qdrant database

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

from langchain_qdrant import Qdrant
from langchain_openai import OpenAIEmbeddings

embeddings = OpenAIEmbeddings()
qdrant = Qdrant.from_texts(texts, embeddings, "localhost")

from_existing_collection classmethod

from_existing_collection(
    embedding: Embeddings,
    path: str | None = None,
    collection_name: str | None = None,
    location: str | None = None,
    url: str | None = None,
    port: int | None = 6333,
    grpc_port: int = 6334,
    prefer_grpc: bool = False,
    https: bool | None = None,
    api_key: str | None = None,
    prefix: str | None = None,
    timeout: int | None = None,
    host: str | None = None,
    content_payload_key: str = CONTENT_KEY,
    metadata_payload_key: str = METADATA_KEY,
    distance_strategy: str = "COSINE",
    vector_name: str | None = VECTOR_NAME,
    **kwargs: Any,
) -> Qdrant

Get instance of an existing Qdrant collection.

This method will return the instance of the store without inserting any new embeddings.

afrom_texts async classmethod

afrom_texts(
    texts: list[str],
    embedding: Embeddings,
    metadatas: list[dict] | None = None,
    ids: Sequence[str] | None = None,
    location: str | None = None,
    url: str | None = None,
    port: int | None = 6333,
    grpc_port: int = 6334,
    prefer_grpc: bool = False,
    https: bool | None = None,
    api_key: str | None = None,
    prefix: str | None = None,
    timeout: int | None = None,
    host: str | None = None,
    path: str | None = None,
    collection_name: str | None = None,
    distance_func: str = "Cosine",
    content_payload_key: str = CONTENT_KEY,
    metadata_payload_key: str = METADATA_KEY,
    vector_name: str | None = VECTOR_NAME,
    batch_size: int = 64,
    shard_number: int | None = None,
    replication_factor: int | None = None,
    write_consistency_factor: int | None = None,
    on_disk_payload: bool | None = None,
    hnsw_config: HnswConfigDiff | None = None,
    optimizers_config: OptimizersConfigDiff | None = None,
    wal_config: WalConfigDiff | None = None,
    quantization_config: QuantizationConfig | None = None,
    init_from: InitFrom | None = None,
    on_disk: bool | None = None,
    force_recreate: bool = False,
    **kwargs: Any,
) -> Qdrant

Construct Qdrant wrapper from a list of texts.

PARAMETER DESCRIPTION
texts

A list of texts to be indexed in Qdrant.

TYPE: list[str]

embedding

A subclass of Embeddings, responsible for text vectorization.

TYPE: Embeddings

metadatas

An optional list of metadata. If provided it has to be of the same length as a list of texts.

TYPE: list[dict] | None DEFAULT: None

ids

Optional list of ids to associate with the texts. Ids have to be uuid-like strings.

TYPE: Sequence[str] | None DEFAULT: None

location

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.

TYPE: str | None DEFAULT: None

url

either host or str of "scheme | None, host, port | None, prefix | None".

TYPE: str | None DEFAULT: None

port

Port of the REST API interface. Default: 6333

TYPE: int | None DEFAULT: 6333

grpc_port

Port of the gRPC interface. Default: 6334

TYPE: int DEFAULT: 6334

prefer_grpc

If true - use gPRC interface whenever possible in custom methods. Default: False

TYPE: bool DEFAULT: False

https

If true - use HTTPS(SSL) protocol. Default: None

TYPE: bool | None DEFAULT: None

api_key
API key for authentication in Qdrant Cloud. Default: None
Can also be set via environment variable `QDRANT_API_KEY`.

TYPE: str | None DEFAULT: None

prefix

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

TYPE: str | None DEFAULT: None

timeout

Timeout for REST and gRPC API requests. Default: 5.0 seconds for REST and unlimited for gRPC

TYPE: int | None DEFAULT: None

host

Host name of Qdrant service. If url and host are None, set to 'localhost'. Default: None

TYPE: str | None DEFAULT: None

path

Path in which the vectors will be stored while using local mode. Default: None

TYPE: str | None DEFAULT: None

collection_name

Name of the Qdrant collection to be used. If not provided, it will be created randomly. Default: None

TYPE: str | None DEFAULT: None

distance_func

Distance function. One of: "Cosine" / "Euclid" / "Dot". Default: "Cosine"

TYPE: str DEFAULT: 'Cosine'

content_payload_key

A payload key used to store the content of the document. Default: "page_content"

TYPE: str DEFAULT: CONTENT_KEY

metadata_payload_key

A payload key used to store the metadata of the document. Default: "metadata"

TYPE: str DEFAULT: METADATA_KEY

vector_name

Name of the vector to be used internally in Qdrant. Default: None

TYPE: str | None DEFAULT: VECTOR_NAME

batch_size

How many vectors upload per-request. Default: 64

TYPE: int DEFAULT: 64

shard_number

Number of shards in collection. Default is 1, minimum is 1.

TYPE: int | None DEFAULT: None

replication_factor

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.

TYPE: int | None DEFAULT: None

write_consistency_factor

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.

TYPE: int | None DEFAULT: None

on_disk_payload

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.

TYPE: bool | None DEFAULT: None

hnsw_config

Params for HNSW index

TYPE: HnswConfigDiff | None DEFAULT: None

optimizers_config

Params for optimizer

TYPE: OptimizersConfigDiff | None DEFAULT: None

wal_config

Params for Write-Ahead-Log

TYPE: WalConfigDiff | None DEFAULT: None

quantization_config

Params for quantization, if None - quantization will be disabled

TYPE: QuantizationConfig | None DEFAULT: None

init_from

Use data stored in another collection to initialize this collection

TYPE: InitFrom | None DEFAULT: None

on_disk

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.

TYPE: bool | None DEFAULT: None

force_recreate

Force recreating the collection

TYPE: bool DEFAULT: False

**kwargs

Additional arguments passed directly into REST client initialization

TYPE: Any DEFAULT: {}

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)
  3. Adds the text embeddings to the Qdrant database

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

from langchain_qdrant import Qdrant
from langchain_openai import OpenAIEmbeddings

embeddings = OpenAIEmbeddings()
qdrant = await Qdrant.afrom_texts(texts, embeddings, "localhost")