langchain-qdrant¶
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.
__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:
|
batch_size
|
Batch size for encoding.
TYPE:
|
cache_dir
|
The path to the model cache directory. Can also be set using the
TYPE:
|
threads
|
The number of threads onnxruntime session can use.
TYPE:
|
providers
|
List of ONNX execution providers. parallel (int, optional): If |
kwargs
|
Additional options to pass to
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the |
QdrantVectorStore
¶
Bases: VectorStore
Qdrant vector store integration.
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)
Search
Search with filter
Search with score
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}]")
Use as Retriever
| 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 |
add_documents |
Add or update documents in the |
aadd_documents |
Async run more documents through the embeddings and add to the |
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 |
asimilarity_search_with_relevance_scores |
Async return docs and relevance scores in the range |
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 |
afrom_documents |
Async return |
afrom_texts |
Async return |
as_retriever |
Return |
__init__ |
Initialize a new instance of |
from_texts |
Construct an instance of |
from_existing_collection |
Construct |
add_texts |
Add texts with embeddings to the |
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
¶
Get the Qdrant client instance that is being used.
| RETURNS | DESCRIPTION |
|---|---|
QdrantClient
|
An instance of
TYPE:
|
embeddings
property
¶
embeddings: Embeddings | None
Get the dense embeddings instance that is being used.
| RETURNS | DESCRIPTION |
|---|---|
Embeddings
|
An instance of
TYPE:
|
sparse_embeddings
property
¶
sparse_embeddings: SparseEmbeddings
Get the sparse embeddings instance that is being used.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If sparse embeddings are |
| RETURNS | DESCRIPTION |
|---|---|
SparseEmbeddings
|
An instance of
TYPE:
|
aget_by_ids
async
¶
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. |
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
adelete
async
¶
Async delete by vector ID or other criteria.
| PARAMETER | DESCRIPTION |
|---|---|
ids
|
List of IDs to delete. If |
**kwargs
|
Other keyword arguments that subclasses might use.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool | None
|
|
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 |
metadatas
|
Optional list of metadatas associated with the texts. |
ids
|
Optional list |
**kwargs
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
List of IDs from adding the texts into the |
| 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 or update documents in the VectorStore.
| PARAMETER | DESCRIPTION |
|---|---|
documents
|
Documents to add to the |
**kwargs
|
Additional keyword arguments. If kwargs contains IDs and documents contain ids, the IDs in the kwargs will receive precedence.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
List of IDs of the added texts. |
aadd_documents
async
¶
search
¶
Return docs most similar to query using a specified search type.
| PARAMETER | DESCRIPTION |
|---|---|
query
|
Input text.
TYPE:
|
search_type
|
Type of search to perform. Can be
TYPE:
|
**kwargs
|
Arguments to pass to the search method.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
asearch
async
¶
Async return docs most similar to query using a specified search type.
| PARAMETER | DESCRIPTION |
|---|---|
query
|
Input text.
TYPE:
|
search_type
|
Type of search to perform. Can be
TYPE:
|
**kwargs
|
Arguments to pass to the search method.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
asimilarity_search_with_score
async
¶
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:
|
k
|
Number of
TYPE:
|
**kwargs
|
kwargs to be passed to similarity search. Should include
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[tuple[Document, float]]
|
List of tuples of |
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:
|
k
|
Number of
TYPE:
|
**kwargs
|
kwargs to be passed to similarity search. Should include
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[tuple[Document, float]]
|
List of tuples of |
asimilarity_search
async
¶
Async return docs most similar to query.
| PARAMETER | DESCRIPTION |
|---|---|
query
|
Input text.
TYPE:
|
k
|
Number of
TYPE:
|
**kwargs
|
Arguments to pass to the search method.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
asimilarity_search_by_vector
async
¶
Async return docs most similar to embedding vector.
| PARAMETER | DESCRIPTION |
|---|---|
embedding
|
Embedding to look up documents similar to. |
k
|
Number of
TYPE:
|
**kwargs
|
Arguments to pass to the search method.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
amax_marginal_relevance_search
async
¶
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:
|
k
|
Number of
TYPE:
|
fetch_k
|
Number of
TYPE:
|
lambda_mult
|
Number between
TYPE:
|
**kwargs
|
Arguments to pass to the search method.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
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. |
k
|
Number of
TYPE:
|
fetch_k
|
Number of
TYPE:
|
lambda_mult
|
Number between
TYPE:
|
**kwargs
|
Arguments to pass to the search method.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
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 |
embedding
|
Embedding function to use.
TYPE:
|
**kwargs
|
Additional keyword arguments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
|
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 |
embedding
|
Embedding function to use.
TYPE:
|
**kwargs
|
Additional keyword arguments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
|
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 |
embedding
|
Embedding function to use.
TYPE:
|
metadatas
|
Optional list of metadatas associated with the texts. |
ids
|
Optional list of IDs associated with the texts. |
**kwargs
|
Additional keyword arguments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
|
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:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
VectorStoreRetriever
|
Retriever class for |
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
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:
- Creates embeddings, one for each text
- Creates a Qdrant collection if it doesn't exist.
- Adds the text embeddings to the Qdrant database
This is intended to be a quick way to get started.
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
TYPE:
|
add_texts
¶
similarity_search
¶
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]]
similarity_search_with_score_by_vector
¶
similarity_search_by_vector
¶
max_marginal_relevance_search
¶
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]
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]]
delete
¶
get_by_ids
¶
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. |
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
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.
aembed_documents
async
¶
aembed_documents(texts: list[str]) -> list[SparseVector]
Asynchronous Embed search docs.
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 |
aadd_documents |
Async run more documents through the embeddings and add to the |
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 |
asimilarity_search_with_relevance_scores |
Async return docs and relevance scores in the range |
from_documents |
Return |
afrom_documents |
Async return |
as_retriever |
Return |
__init__ |
Initialize with necessary components. |
add_texts |
Run more texts through the embeddings and add to the |
aadd_texts |
Run more texts through the embeddings and add to the |
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. |
get_by_ids
¶
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. |
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
aget_by_ids
async
¶
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. |
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
add_documents
¶
Add or update documents in the VectorStore.
| PARAMETER | DESCRIPTION |
|---|---|
documents
|
Documents to add to the |
**kwargs
|
Additional keyword arguments. If kwargs contains IDs and documents contain ids, the IDs in the kwargs will receive precedence.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
List of IDs of the added texts. |
aadd_documents
async
¶
search
¶
Return docs most similar to query using a specified search type.
| PARAMETER | DESCRIPTION |
|---|---|
query
|
Input text.
TYPE:
|
search_type
|
Type of search to perform. Can be
TYPE:
|
**kwargs
|
Arguments to pass to the search method.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
asearch
async
¶
Async return docs most similar to query using a specified search type.
| PARAMETER | DESCRIPTION |
|---|---|
query
|
Input text.
TYPE:
|
search_type
|
Type of search to perform. Can be
TYPE:
|
**kwargs
|
Arguments to pass to the search method.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
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:
|
k
|
Number of
TYPE:
|
**kwargs
|
kwargs to be passed to similarity search. Should include
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[tuple[Document, float]]
|
List of tuples of |
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:
|
k
|
Number of
TYPE:
|
**kwargs
|
kwargs to be passed to similarity search. Should include
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[tuple[Document, float]]
|
List of tuples of |
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 |
embedding
|
Embedding function to use.
TYPE:
|
**kwargs
|
Additional keyword arguments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
|
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 |
embedding
|
Embedding function to use.
TYPE:
|
**kwargs
|
Additional keyword arguments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
|
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:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
VectorStoreRetriever
|
Retriever class for |
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 |
metadatas
|
Optional list of metadatas associated with the texts. |
ids
|
Optional list of ids to associate with the texts. Ids have to be uuid-like strings. |
batch_size
|
How many vectors upload per-request.
Default:
TYPE:
|
**kwargs
|
Additional keyword arguments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
List of ids from adding the texts into the |
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 |
metadatas
|
Optional list of metadatas associated with the texts. |
ids
|
Optional list of ids to associate with the texts. Ids have to be uuid-like strings. |
batch_size
|
How many vectors upload per-request.
Default:
TYPE:
|
**kwargs
|
Additional keyword arguments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
List of ids from adding the texts into the |
similarity_search
¶
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:
|
k
|
Number of Documents to return.
TYPE:
|
filter
|
Filter by metadata.
TYPE:
|
search_params
|
Additional search params
TYPE:
|
offset
|
Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues.
TYPE:
|
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:
|
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:
|
**kwargs
|
Any other named arguments to pass through to QdrantClient.search()
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
asimilarity_search
async
¶
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:
|
k
|
Number of Documents to return.
TYPE:
|
filter
|
Filter by metadata.
TYPE:
|
**kwargs
|
Additional keyword arguments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
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:
|
k
|
Number of Documents to return.
TYPE:
|
filter
|
Filter by metadata.
TYPE:
|
search_params
|
Additional search params
TYPE:
|
offset
|
Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues.
TYPE:
|
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:
|
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:
|
**kwargs
|
Any other named arguments to pass through to QdrantClient.search()
TYPE:
|
| 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:
|
k
|
Number of Documents to return.
TYPE:
|
filter
|
Filter by metadata.
TYPE:
|
search_params
|
Additional search params
TYPE:
|
offset
|
Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues.
TYPE:
|
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:
|
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:
|
**kwargs
|
Any other named arguments to pass through to AsyncQdrantClient.Search().
TYPE:
|
| 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. |
k
|
Number of Documents to return.
TYPE:
|
filter
|
Filter by metadata.
TYPE:
|
search_params
|
Additional search params
TYPE:
|
offset
|
Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues.
TYPE:
|
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:
|
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:
|
**kwargs
|
Any other named arguments to pass through to QdrantClient.search()
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
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. |
k
|
Number of Documents to return.
TYPE:
|
filter
|
Filter by metadata.
TYPE:
|
search_params
|
Additional search params
TYPE:
|
offset
|
Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues.
TYPE:
|
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:
|
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:
|
**kwargs
|
Any other named arguments to pass through to AsyncQdrantClient.Search().
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
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. |
k
|
Number of Documents to return.
TYPE:
|
filter
|
Filter by metadata.
TYPE:
|
search_params
|
Additional search params
TYPE:
|
offset
|
Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues.
TYPE:
|
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:
|
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:
|
**kwargs
|
Any other named arguments to pass through to QdrantClient.search()
TYPE:
|
| 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. |
k
|
Number of Documents to return.
TYPE:
|
filter
|
Filter by metadata.
TYPE:
|
search_params
|
Additional search params
TYPE:
|
offset
|
Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues.
TYPE:
|
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:
|
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:
|
**kwargs
|
Any other named arguments to pass through to AsyncQdrantClient.Search().
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[tuple[Document, float]]
|
List of documents most similar to the query text and distance for each. |
max_marginal_relevance_search
¶
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:
|
k
|
Number of Documents to return.
TYPE:
|
fetch_k
|
Number of Documents to fetch to pass to MMR algorithm.
TYPE:
|
lambda_mult
|
Number between
TYPE:
|
filter
|
Filter by metadata.
TYPE:
|
search_params
|
Additional search params
TYPE:
|
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:
|
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:
|
**kwargs
|
Any other named arguments to pass through to QdrantClient.search()
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
amax_marginal_relevance_search
async
¶
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:
|
k
|
Number of Documents to return.
TYPE:
|
fetch_k
|
Number of Documents to fetch to pass to MMR algorithm.
TYPE:
|
lambda_mult
|
Number between
TYPE:
|
filter
|
Filter by metadata.
TYPE:
|
search_params
|
Additional search params
TYPE:
|
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:
|
consistency
|
Read consistency of the search. Defines how many replicas should be
queried before returning the result.
Values:
-
TYPE:
|
**kwargs
|
Any other named arguments to pass through to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
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. |
k
|
Number of Documents to return.
TYPE:
|
fetch_k
|
Number of Documents to fetch to pass to MMR algorithm.
TYPE:
|
lambda_mult
|
Number between
TYPE:
|
filter
|
Filter by metadata.
TYPE:
|
search_params
|
Additional search params
TYPE:
|
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:
|
consistency
|
Read consistency of the search. Defines how many replicas should be
queried before returning the result.
Values:
-
TYPE:
|
**kwargs
|
Any other named arguments to pass through to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
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. |
k
|
Number of
TYPE:
|
fetch_k
|
Number of
TYPE:
|
lambda_mult
|
Number between
TYPE:
|
filter
|
Filter by metadata.
TYPE:
|
search_params
|
Additional search params
TYPE:
|
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:
|
consistency
|
Read consistency of the search. Defines how many replicas should be
queried before returning the result.
Values:
-
TYPE:
|
**kwargs
|
Any other named arguments to pass through to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Document]
|
List of |
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. |
k
|
Number of Documents to return.
TYPE:
|
fetch_k
|
Number of Documents to fetch to pass to MMR algorithm.
TYPE:
|
lambda_mult
|
Number between
TYPE:
|
filter
|
Filter by metadata.
TYPE:
|
search_params
|
Additional search params
TYPE:
|
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:
|
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:
|
**kwargs
|
Any other named arguments to pass through to QdrantClient.search()
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[tuple[Document, float]]
|
List of |
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. |
k
|
Number of Documents to return.
TYPE:
|
fetch_k
|
Number of Documents to fetch to pass to MMR algorithm.
TYPE:
|
lambda_mult
|
Number between
TYPE:
|
filter
|
Filter by metadata.
TYPE:
|
search_params
|
Additional search params.
TYPE:
|
score_threshold
|
Define a minimal score threshold for the result.
TYPE:
|
consistency
|
Read consistency of the search.
TYPE:
|
**kwargs
|
Additional keyword arguments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[tuple[Document, float]]
|
List of |
delete
¶
adelete
async
¶
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. |
embedding
|
A subclass of
TYPE:
|
metadatas
|
An optional list of metadata. If provided it has to be of the same length as a list of texts. |
ids
|
Optional list of ids to associate with the texts. Ids have to be uuid-like strings. |
location
|
If ':memory:' - use in-memory Qdrant instance.
If
TYPE:
|
url
|
either host or str of "scheme | None, host, port | None, prefix | None".
TYPE:
|
port
|
Port of the REST API interface. Default: 6333
TYPE:
|
grpc_port
|
Port of the gRPC interface. Default: 6334
TYPE:
|
prefer_grpc
|
If true - use gPRC interface whenever possible in custom methods. Default: False
TYPE:
|
https
|
If true - use HTTPS(SSL) protocol. Default: None
TYPE:
|
api_key
|
TYPE:
|
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:
|
timeout
|
Timeout for REST and gRPC API requests. Default: 5.0 seconds for REST and unlimited for gRPC
TYPE:
|
host
|
Host name of Qdrant service. If url and host are None, set to 'localhost'. Default: None
TYPE:
|
path
|
Path in which the vectors will be stored while using local mode. Default: None
TYPE:
|
collection_name
|
Name of the Qdrant collection to be used. If not provided, it will be created randomly. Default: None
TYPE:
|
distance_func
|
Distance function. One of: "Cosine" / "Euclid" / "Dot". Default: "Cosine"
TYPE:
|
content_payload_key
|
A payload key used to store the content of the document. Default: "page_content"
TYPE:
|
metadata_payload_key
|
A payload key used to store the metadata of the document. Default: "metadata"
TYPE:
|
vector_name
|
Name of the vector to be used internally in Qdrant. Default: None
TYPE:
|
batch_size
|
How many vectors upload per-request. Default: 64
TYPE:
|
shard_number
|
Number of shards in collection. Default is 1, minimum is 1.
TYPE:
|
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:
|
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:
|
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:
|
hnsw_config
|
Params for HNSW index
TYPE:
|
optimizers_config
|
Params for optimizer
TYPE:
|
wal_config
|
Params for Write-Ahead-Log
TYPE:
|
quantization_config
|
Params for quantization, if None - quantization will be disabled
TYPE:
|
init_from
|
Use data stored in another collection to initialize this collection
TYPE:
|
on_disk
|
If true - vectors will be stored on disk, reducing memory usage.
TYPE:
|
force_recreate
|
Force recreating the collection
TYPE:
|
**kwargs
|
Additional arguments passed directly into REST client initialization
TYPE:
|
This is a user-friendly interface that:
- Creates embeddings, one for each text
- Initializes the Qdrant database as an in-memory docstore by default (and overridable to a remote docstore)
- Adds the text embeddings to the Qdrant database
This is intended to be a quick way to get started.
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. |
embedding
|
A subclass of
TYPE:
|
metadatas
|
An optional list of metadata. If provided it has to be of the same length as a list of texts. |
ids
|
Optional list of ids to associate with the texts. Ids have to be uuid-like strings. |
location
|
If ':memory:' - use in-memory Qdrant instance.
If
TYPE:
|
url
|
either host or str of "scheme | None, host, port | None, prefix | None".
TYPE:
|
port
|
Port of the REST API interface. Default: 6333
TYPE:
|
grpc_port
|
Port of the gRPC interface. Default: 6334
TYPE:
|
prefer_grpc
|
If true - use gPRC interface whenever possible in custom methods. Default: False
TYPE:
|
https
|
If true - use HTTPS(SSL) protocol. Default: None
TYPE:
|
api_key
|
TYPE:
|
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:
|
timeout
|
Timeout for REST and gRPC API requests. Default: 5.0 seconds for REST and unlimited for gRPC
TYPE:
|
host
|
Host name of Qdrant service. If url and host are None, set to 'localhost'. Default: None
TYPE:
|
path
|
Path in which the vectors will be stored while using local mode. Default: None
TYPE:
|
collection_name
|
Name of the Qdrant collection to be used. If not provided, it will be created randomly. Default: None
TYPE:
|
distance_func
|
Distance function. One of: "Cosine" / "Euclid" / "Dot". Default: "Cosine"
TYPE:
|
content_payload_key
|
A payload key used to store the content of the document. Default: "page_content"
TYPE:
|
metadata_payload_key
|
A payload key used to store the metadata of the document. Default: "metadata"
TYPE:
|
vector_name
|
Name of the vector to be used internally in Qdrant. Default: None
TYPE:
|
batch_size
|
How many vectors upload per-request. Default: 64
TYPE:
|
shard_number
|
Number of shards in collection. Default is 1, minimum is 1.
TYPE:
|
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:
|
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:
|
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:
|
hnsw_config
|
Params for HNSW index
TYPE:
|
optimizers_config
|
Params for optimizer
TYPE:
|
wal_config
|
Params for Write-Ahead-Log
TYPE:
|
quantization_config
|
Params for quantization, if None - quantization will be disabled
TYPE:
|
init_from
|
Use data stored in another collection to initialize this collection
TYPE:
|
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:
|
force_recreate
|
Force recreating the collection
TYPE:
|
**kwargs
|
Additional arguments passed directly into REST client initialization
TYPE:
|
This is a user-friendly interface that:
- Creates embeddings, one for each text
- Initializes the Qdrant database as an in-memory docstore by default (and overridable to a remote docstore)
- Adds the text embeddings to the Qdrant database
This is intended to be a quick way to get started.