langchain-qdrant
¶
Modules:
Name | Description |
---|---|
fastembed_sparse |
|
qdrant |
|
sparse_embeddings |
|
vectorstores |
|
Classes:
Name | Description |
---|---|
FastEmbedSparse |
An interface for sparse embedding models to use with Qdrant. |
QdrantVectorStore |
Qdrant vector store integration. |
RetrievalMode |
Modes for retrieving vectors from Qdrant. |
SparseEmbeddings |
An interface for sparse embedding models to use with Qdrant. |
SparseVector |
Sparse vector structure. |
Qdrant |
|
FastEmbedSparse
¶
Bases: SparseEmbeddings
An interface for sparse embedding models to use with Qdrant.
Methods:
Name | Description |
---|---|
aembed_documents |
Asynchronous Embed search docs. |
aembed_query |
Asynchronous Embed query text. |
__init__ |
Sparse encoder implementation using FastEmbed. |
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: Optional[str] = None,
threads: Optional[int] = None,
providers: Optional[Sequence[Any]] = None,
parallel: Optional[int] = None,
**kwargs: Any
) -> None
Sparse encoder implementation using FastEmbed.
Uses FastEmbed <https://qdrant.github.io/fastembed/>
__ for sparse text
embeddings.
For a list of available models, see the Qdrant docs <https://qdrant.github.io/fastembed/examples/Supported_Models/>
__.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_name
|
str
|
The name of the model to use. Defaults to |
'Qdrant/bm25'
|
batch_size
|
int
|
Batch size for encoding. Defaults to 256. |
256
|
cache_dir
|
str
|
The path to the model cache directory. Can also be set using the |
None
|
threads
|
int
|
The number of threads onnxruntime session can use. |
None
|
providers
|
Sequence[Any]
|
List of ONNX execution providers. parallel (int, optional): If |
None
|
kwargs
|
Any
|
Additional options to pass to fastembed.SparseTextEmbedding |
{}
|
Raises: ValueError: If the model_name is not supported in SparseTextEmbedding.
QdrantVectorStore
¶
Bases: VectorStore
Qdrant vector store integration.
Setup
Install langchain-qdrant
package.
.. code-block:: bash
pip install -qU langchain-qdrant
Key init args — indexing params: collection_name: str Name of the collection. embedding: Embeddings Embedding function to use. sparse_embedding: SparseEmbeddings Optional sparse embedding function to use.
Key init args — client params: client: QdrantClient Qdrant client to use. retrieval_mode: RetrievalMode Retrieval mode to use.
Instantiate
.. code-block:: python
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
.. code-block:: python
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
.. code-block:: python
vector_store.delete(ids=[ids[-1]])
Search
.. code-block:: python
results = vector_store.similarity_search(
query="thud",
k=1,
)
for doc in results:
print(f"* {doc.page_content} [{doc.metadata}]")
.. code-block:: python
*thud[
{
"bar": "baz",
"_id": "0d706099-6dd9-412a-9df6-a71043e020de",
"_collection_name": "demo_collection",
}
]
Search with filter
.. code-block:: python
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}]")
.. code-block:: python
*thud[
{
"bar": "baz",
"_id": "0d706099-6dd9-412a-9df6-a71043e020de",
"_collection_name": "demo_collection",
}
]
Search with score
.. code-block:: python
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}]")
.. code-block:: python
* [SIM=0.832268] foo [{'baz': 'bar', '_id': '44ec7094-b061-45ac-8fbf-014b0f18e8aa', '_collection_name': 'demo_collection'}]
Async
.. code-block:: python
# 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}]")
.. code-block:: python
* [SIM=0.832268] foo [{'baz': 'bar', '_id': '44ec7094-b061-45ac-8fbf-014b0f18e8aa', '_collection_name': 'demo_collection'}]
Use as Retriever
.. code-block:: python
retriever = vector_store.as_retriever(
search_type="mmr",
search_kwargs={"k": 1, "fetch_k": 2, "lambda_mult": 0.5},
)
retriever.invoke("thud")
.. code-block:: python
[
Document(
metadata={
"bar": "baz",
"_id": "0d706099-6dd9-412a-9df6-a71043e020de",
"_collection_name": "demo_collection",
},
page_content="thud",
)
]
Methods:
Name | 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 |
from_texts |
Construct an instance of |
from_existing_collection |
Construct |
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. |
Attributes:
Name | Type | Description |
---|---|---|
client |
QdrantClient
|
Get the Qdrant client instance that is being used. |
embeddings |
Optional[Embeddings]
|
Get the dense embeddings instance that is being used. |
sparse_embeddings |
SparseEmbeddings
|
Get the sparse embeddings instance that is being used. |
client
property
¶
Get the Qdrant client instance that is being used.
Returns:
Name | Type | Description |
---|---|---|
QdrantClient |
QdrantClient
|
An instance of |
embeddings
property
¶
embeddings: Optional[Embeddings]
Get the dense embeddings instance that is being used.
Returns:
Name | Type | Description |
---|---|---|
Embeddings |
Optional[Embeddings]
|
An instance of |
sparse_embeddings
property
¶
sparse_embeddings: SparseEmbeddings
Get the sparse embeddings instance that is being used.
Raises:
Type | Description |
---|---|
ValueError
|
If sparse embeddings are |
Returns:
Name | Type | Description |
---|---|---|
SparseEmbeddings |
SparseEmbeddings
|
An instance 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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ids
|
Sequence[str]
|
List of ids to retrieve. |
required |
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents. |
Added in version 0.2.11
adelete
async
¶
Async delete by vector ID or other criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ids
|
list[str] | None
|
List of ids to delete. If None, delete all. Default is None. |
None
|
**kwargs
|
Any
|
Other keyword arguments that subclasses might use. |
{}
|
Returns:
Type | Description |
---|---|
bool | None
|
Optional[bool]: True if deletion is successful, |
bool | None
|
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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
texts
|
Iterable[str]
|
Iterable of strings to add to the vectorstore. |
required |
metadatas
|
list[dict] | None
|
Optional list of metadatas associated with the texts. Default is None. |
None
|
ids
|
list[str] | None
|
Optional list |
None
|
**kwargs
|
Any
|
vectorstore specific parameters. |
{}
|
Returns:
Type | Description |
---|---|
list[str]
|
List of ids from adding the texts into the vectorstore. |
Raises:
Type | 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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
documents
|
list[Document]
|
Documents to add to the vectorstore. |
required |
kwargs
|
Any
|
Additional keyword arguments. if kwargs contains ids and documents contain ids, the ids in the kwargs will receive precedence. |
{}
|
Returns:
Type | Description |
---|---|
list[str]
|
List of IDs of the added texts. |
aadd_documents
async
¶
Async run more documents through the embeddings and add to the vectorstore.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
documents
|
list[Document]
|
Documents to add to the vectorstore. |
required |
kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Returns:
Type | Description |
---|---|
list[str]
|
List of IDs of the added texts. |
search
¶
Return docs most similar to query using a specified search type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
Input text |
required |
search_type
|
str
|
Type of search to perform. Can be "similarity", "mmr", or "similarity_score_threshold". |
required |
**kwargs
|
Any
|
Arguments to pass to the search method. |
{}
|
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents most similar to the query. |
Raises:
Type | Description |
---|---|
ValueError
|
If search_type is not one of "similarity", "mmr", or "similarity_score_threshold". |
asearch
async
¶
Async return docs most similar to query using a specified search type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
Input text. |
required |
search_type
|
str
|
Type of search to perform. Can be "similarity", "mmr", or "similarity_score_threshold". |
required |
**kwargs
|
Any
|
Arguments to pass to the search method. |
{}
|
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents most similar to the query. |
Raises:
Type | Description |
---|---|
ValueError
|
If search_type is not one of "similarity", "mmr", or "similarity_score_threshold". |
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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
Input text. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
**kwargs
|
Any
|
kwargs to be passed to similarity search. Should include: score_threshold: Optional, a floating point value between 0 to 1 to filter the resulting set of retrieved docs. |
{}
|
Returns:
Type | 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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
Input text. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
**kwargs
|
Any
|
kwargs to be passed to similarity search. Should include: score_threshold: Optional, a floating point value between 0 to 1 to filter the resulting set of retrieved docs |
{}
|
Returns:
Type | Description |
---|---|
list[tuple[Document, float]]
|
List of Tuples of (doc, similarity_score) |
asimilarity_search
async
¶
Async return docs most similar to query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
Input text. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
**kwargs
|
Any
|
Arguments to pass to the search method. |
{}
|
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents most similar to the query. |
asimilarity_search_by_vector
async
¶
Async return docs most similar to embedding vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embedding
|
list[float]
|
Embedding to look up documents similar to. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
**kwargs
|
Any
|
Arguments to pass to the search method. |
{}
|
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents most similar to the query vector. |
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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
Text to look up documents similar to. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
fetch_k
|
int
|
Number of Documents to fetch to pass to MMR algorithm. Default is 20. |
20
|
lambda_mult
|
float
|
Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. |
0.5
|
**kwargs
|
Any
|
Arguments to pass to the search method. |
{}
|
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents 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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embedding
|
list[float]
|
Embedding to look up documents similar to. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
fetch_k
|
int
|
Number of Documents to fetch to pass to MMR algorithm. Default is 20. |
20
|
lambda_mult
|
float
|
Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. |
0.5
|
**kwargs
|
Any
|
Arguments to pass to the search method. |
{}
|
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents 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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
documents
|
list[Document]
|
List of Documents to add to the vectorstore. |
required |
embedding
|
Embeddings
|
Embedding function to use. |
required |
kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
VectorStore |
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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
documents
|
list[Document]
|
List of Documents to add to the vectorstore. |
required |
embedding
|
Embeddings
|
Embedding function to use. |
required |
kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
VectorStore |
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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
texts
|
list[str]
|
Texts to add to the vectorstore. |
required |
embedding
|
Embeddings
|
Embedding function to use. |
required |
metadatas
|
list[dict] | None
|
Optional list of metadatas associated with the texts. Default is None. |
None
|
ids
|
list[str] | None
|
Optional list of IDs associated with the texts. |
None
|
kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
VectorStore |
Self
|
VectorStore initialized from texts and embeddings. |
as_retriever
¶
as_retriever(**kwargs: Any) -> VectorStoreRetriever
Return VectorStoreRetriever initialized from this VectorStore.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Any
|
Keyword arguments to pass to the search function. Can include: search_type (Optional[str]): Defines the type of search that the Retriever should perform. Can be "similarity" (default), "mmr", or "similarity_score_threshold". search_kwargs (Optional[Dict]): Keyword arguments to pass to the search function. Can include things like: k: Amount of documents to return (Default: 4) score_threshold: Minimum relevance threshold for similarity_score_threshold fetch_k: Amount of documents to pass to MMR algorithm (Default: 20) lambda_mult: Diversity of results returned by MMR; 1 for minimum diversity and 0 for maximum. (Default: 0.5) filter: Filter by document metadata |
{}
|
Returns:
Name | Type | Description |
---|---|---|
VectorStoreRetriever |
VectorStoreRetriever
|
Retriever class for VectorStore. |
Examples:
.. code-block:: python
# 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: Optional[Embeddings] = 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: Optional[SparseEmbeddings] = None,
sparse_vector_name: str = SPARSE_VECTOR_NAME,
validate_embeddings: bool = True,
validate_collection_config: bool = True,
) -> None
Initialize a new instance of QdrantVectorStore
.
Example
.. code-block:: python 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: Optional[Embeddings] = None,
metadatas: Optional[list[dict]] = None,
ids: Optional[Sequence[str | int]] = None,
collection_name: Optional[str] = None,
location: Optional[str] = None,
url: Optional[str] = None,
port: Optional[int] = 6333,
grpc_port: int = 6334,
prefer_grpc: bool = False,
https: Optional[bool] = None,
api_key: Optional[str] = None,
prefix: Optional[str] = None,
timeout: Optional[int] = None,
host: Optional[str] = None,
path: Optional[str] = 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: Optional[SparseEmbeddings] = None,
sparse_vector_name: str = SPARSE_VECTOR_NAME,
collection_create_options: Optional[
dict[str, Any]
] = None,
vector_params: Optional[dict[str, Any]] = None,
sparse_vector_params: Optional[dict[str, Any]] = 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.
Example
.. code-block:: python
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: Optional[Embeddings] = None,
retrieval_mode: RetrievalMode = DENSE,
location: Optional[str] = None,
url: Optional[str] = None,
port: Optional[int] = 6333,
grpc_port: int = 6334,
prefer_grpc: bool = False,
https: Optional[bool] = None,
api_key: Optional[str] = None,
prefix: Optional[str] = None,
timeout: Optional[int] = None,
host: Optional[str] = None,
path: Optional[str] = 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: Optional[SparseEmbeddings] = None,
validate_embeddings: bool = True,
validate_collection_config: bool = True,
**kwargs: Any
) -> QdrantVectorStore
Construct QdrantVectorStore
from existing collection without adding data.
Returns:
Name | Type | Description |
---|---|---|
QdrantVectorStore |
QdrantVectorStore
|
A new instance of |
add_texts
¶
similarity_search
¶
similarity_search(
query: str,
k: int = 4,
filter: Optional[Filter] = None,
search_params: Optional[SearchParams] = None,
offset: int = 0,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = None,
hybrid_fusion: Optional[FusionQuery] = None,
**kwargs: Any
) -> list[Document]
Return docs most similar to query.
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents most similar to the query. |
similarity_search_with_score
¶
similarity_search_with_score(
query: str,
k: int = 4,
filter: Optional[Filter] = None,
search_params: Optional[SearchParams] = None,
offset: int = 0,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = None,
hybrid_fusion: Optional[FusionQuery] = None,
**kwargs: Any
) -> list[tuple[Document, float]]
similarity_search_with_score_by_vector
¶
similarity_search_with_score_by_vector(
embedding: list[float],
k: int = 4,
filter: Optional[Filter] = None,
search_params: Optional[SearchParams] = None,
offset: int = 0,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = None,
**kwargs: Any
) -> list[tuple[Document, float]]
similarity_search_by_vector
¶
similarity_search_by_vector(
embedding: list[float],
k: int = 4,
filter: Optional[Filter] = None,
search_params: Optional[SearchParams] = None,
offset: int = 0,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = None,
**kwargs: Any
) -> list[Document]
Return docs most similar to embedding vector.
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents most similar to the query. |
max_marginal_relevance_search
¶
max_marginal_relevance_search(
query: str,
k: int = 4,
fetch_k: int = 20,
lambda_mult: float = 0.5,
filter: Optional[Filter] = None,
search_params: Optional[SearchParams] = None,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = 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:
Type | Description |
---|---|
list[Document]
|
List of Documents 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: Optional[Filter] = None,
search_params: Optional[SearchParams] = None,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = 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:
Type | Description |
---|---|
list[Document]
|
List of Documents 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: Optional[Filter] = None,
search_params: Optional[SearchParams] = None,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = 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:
Type | Description |
---|---|
list[tuple[Document, float]]
|
List of Documents selected by maximal marginal relevance and distance for |
list[tuple[Document, float]]
|
each. |
delete
¶
SparseEmbeddings
¶
Bases: ABC
An interface for sparse embedding models to use with Qdrant.
Methods:
Name | 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.
SparseVector
¶
Bases: BaseModel
Sparse vector structure.
Qdrant
¶
Bases: VectorStore
Qdrant
vector store.
Example
.. code-block:: python
from qdrant_client import QdrantClient
from langchain_qdrant import Qdrant
client = QdrantClient()
collection_name = "MyCollection"
qdrant = Qdrant(client, collection_name, embedding_function)
Methods:
Name | 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. |
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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ids
|
Sequence[str]
|
List of ids to retrieve. |
required |
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents. |
Added in version 0.2.11
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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ids
|
Sequence[str]
|
List of ids to retrieve. |
required |
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents. |
Added in version 0.2.11
add_documents
¶
Add or update documents in the vectorstore.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
documents
|
list[Document]
|
Documents to add to the vectorstore. |
required |
kwargs
|
Any
|
Additional keyword arguments. if kwargs contains ids and documents contain ids, the ids in the kwargs will receive precedence. |
{}
|
Returns:
Type | Description |
---|---|
list[str]
|
List of IDs of the added texts. |
aadd_documents
async
¶
Async run more documents through the embeddings and add to the vectorstore.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
documents
|
list[Document]
|
Documents to add to the vectorstore. |
required |
kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Returns:
Type | Description |
---|---|
list[str]
|
List of IDs of the added texts. |
search
¶
Return docs most similar to query using a specified search type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
Input text |
required |
search_type
|
str
|
Type of search to perform. Can be "similarity", "mmr", or "similarity_score_threshold". |
required |
**kwargs
|
Any
|
Arguments to pass to the search method. |
{}
|
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents most similar to the query. |
Raises:
Type | Description |
---|---|
ValueError
|
If search_type is not one of "similarity", "mmr", or "similarity_score_threshold". |
asearch
async
¶
Async return docs most similar to query using a specified search type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
Input text. |
required |
search_type
|
str
|
Type of search to perform. Can be "similarity", "mmr", or "similarity_score_threshold". |
required |
**kwargs
|
Any
|
Arguments to pass to the search method. |
{}
|
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents most similar to the query. |
Raises:
Type | 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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
Input text. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
**kwargs
|
Any
|
kwargs to be passed to similarity search. Should include: score_threshold: Optional, a floating point value between 0 to 1 to filter the resulting set of retrieved docs. |
{}
|
Returns:
Type | 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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
Input text. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
**kwargs
|
Any
|
kwargs to be passed to similarity search. Should include: score_threshold: Optional, a floating point value between 0 to 1 to filter the resulting set of retrieved docs |
{}
|
Returns:
Type | 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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
documents
|
list[Document]
|
List of Documents to add to the vectorstore. |
required |
embedding
|
Embeddings
|
Embedding function to use. |
required |
kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
VectorStore |
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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
documents
|
list[Document]
|
List of Documents to add to the vectorstore. |
required |
embedding
|
Embeddings
|
Embedding function to use. |
required |
kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
VectorStore |
Self
|
VectorStore initialized from documents and embeddings. |
as_retriever
¶
as_retriever(**kwargs: Any) -> VectorStoreRetriever
Return VectorStoreRetriever initialized from this VectorStore.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Any
|
Keyword arguments to pass to the search function. Can include: search_type (Optional[str]): Defines the type of search that the Retriever should perform. Can be "similarity" (default), "mmr", or "similarity_score_threshold". search_kwargs (Optional[Dict]): Keyword arguments to pass to the search function. Can include things like: k: Amount of documents to return (Default: 4) score_threshold: Minimum relevance threshold for similarity_score_threshold fetch_k: Amount of documents to pass to MMR algorithm (Default: 20) lambda_mult: Diversity of results returned by MMR; 1 for minimum diversity and 0 for maximum. (Default: 0.5) filter: Filter by document metadata |
{}
|
Returns:
Name | Type | Description |
---|---|---|
VectorStoreRetriever |
VectorStoreRetriever
|
Retriever class for VectorStore. |
Examples:
.. code-block:: python
# 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: Optional[Embeddings] = None,
content_payload_key: str = CONTENT_KEY,
metadata_payload_key: str = METADATA_KEY,
distance_strategy: str = "COSINE",
vector_name: Optional[str] = VECTOR_NAME,
async_client: Optional[Any] = None,
embedding_function: Optional[Callable] = None,
) -> None
Initialize with necessary components.
add_texts
¶
add_texts(
texts: Iterable[str],
metadatas: Optional[list[dict]] = None,
ids: Optional[Sequence[str]] = None,
batch_size: int = 64,
**kwargs: Any
) -> list[str]
Run more texts through the embeddings and add to the vectorstore.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
texts
|
Iterable[str]
|
Iterable of strings to add to the vectorstore. |
required |
metadatas
|
Optional[list[dict]]
|
Optional list of metadatas associated with the texts. |
None
|
ids
|
Optional[Sequence[str]]
|
Optional list of ids to associate with the texts. Ids have to be uuid-like strings. |
None
|
batch_size
|
int
|
How many vectors upload per-request.
Default: |
64
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Returns:
Type | Description |
---|---|
list[str]
|
List of ids from adding the texts into the vectorstore. |
aadd_texts
async
¶
aadd_texts(
texts: Iterable[str],
metadatas: Optional[list[dict]] = None,
ids: Optional[Sequence[str]] = None,
batch_size: int = 64,
**kwargs: Any
) -> list[str]
Run more texts through the embeddings and add to the vectorstore.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
texts
|
Iterable[str]
|
Iterable of strings to add to the vectorstore. |
required |
metadatas
|
Optional[list[dict]]
|
Optional list of metadatas associated with the texts. |
None
|
ids
|
Optional[Sequence[str]]
|
Optional list of ids to associate with the texts. Ids have to be uuid-like strings. |
None
|
batch_size
|
int
|
How many vectors upload per-request.
Default: |
64
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Returns:
Type | Description |
---|---|
list[str]
|
List of ids from adding the texts into the vectorstore. |
similarity_search
¶
similarity_search(
query: str,
k: int = 4,
filter: Optional[MetadataFilter] = None,
search_params: Optional[SearchParams] = None,
offset: int = 0,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = None,
**kwargs: Any
) -> list[Document]
Return docs most similar to query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
Text to look up documents similar to. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
filter
|
Optional[MetadataFilter]
|
Filter by metadata. Defaults to None. |
None
|
search_params
|
Optional[SearchParams]
|
Additional search params |
None
|
offset
|
int
|
Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues. |
0
|
score_threshold
|
Optional[float]
|
Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned. |
None
|
consistency
|
Optional[ReadConsistency]
|
Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all queried replicas - 'majority' - query all replicas, but return values present in the majority of replicas - 'quorum' - query the majority of replicas, return values present in all of them - 'all' - query all replicas, and return values present in all replicas |
None
|
**kwargs
|
Any
|
Any other named arguments to pass through to QdrantClient.search() |
{}
|
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents most similar to the query. |
asimilarity_search
async
¶
asimilarity_search(
query: str,
k: int = 4,
filter: Optional[MetadataFilter] = None,
**kwargs: Any
) -> list[Document]
Return docs most similar to query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
Text to look up documents similar to. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
filter
|
Optional[MetadataFilter]
|
Filter by metadata. Defaults to None. |
None
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents most similar to the query. |
similarity_search_with_score
¶
similarity_search_with_score(
query: str,
k: int = 4,
filter: Optional[MetadataFilter] = None,
search_params: Optional[SearchParams] = None,
offset: int = 0,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = None,
**kwargs: Any
) -> list[tuple[Document, float]]
Return docs most similar to query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
Text to look up documents similar to. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
filter
|
Optional[MetadataFilter]
|
Filter by metadata. Defaults to None. |
None
|
search_params
|
Optional[SearchParams]
|
Additional search params |
None
|
offset
|
int
|
Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues. |
0
|
score_threshold
|
Optional[float]
|
Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned. |
None
|
consistency
|
Optional[ReadConsistency]
|
Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all queried replicas - 'majority' - query all replicas, but return values present in the majority of replicas - 'quorum' - query the majority of replicas, return values present in all of them - 'all' - query all replicas, and return values present in all replicas |
None
|
**kwargs
|
Any
|
Any other named arguments to pass through to QdrantClient.search() |
{}
|
Returns:
Type | 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: Optional[MetadataFilter] = None,
search_params: Optional[SearchParams] = None,
offset: int = 0,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = None,
**kwargs: Any
) -> list[tuple[Document, float]]
Return docs most similar to query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
Text to look up documents similar to. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
filter
|
Optional[MetadataFilter]
|
Filter by metadata. Defaults to None. |
None
|
search_params
|
Optional[SearchParams]
|
Additional search params |
None
|
offset
|
int
|
Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues. |
0
|
score_threshold
|
Optional[float]
|
Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned. |
None
|
consistency
|
Optional[ReadConsistency]
|
Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all queried replicas - 'majority' - query all replicas, but return values present in the majority of replicas - 'quorum' - query the majority of replicas, return values present in all of them - 'all' - query all replicas, and return values present in all replicas |
None
|
**kwargs
|
Any
|
Any other named arguments to pass through to AsyncQdrantClient.Search(). |
{}
|
Returns:
Type | 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: Optional[MetadataFilter] = None,
search_params: Optional[SearchParams] = None,
offset: int = 0,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = None,
**kwargs: Any
) -> list[Document]
Return docs most similar to embedding vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embedding
|
list[float]
|
Embedding vector to look up documents similar to. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
filter
|
Optional[MetadataFilter]
|
Filter by metadata. Defaults to None. |
None
|
search_params
|
Optional[SearchParams]
|
Additional search params |
None
|
offset
|
int
|
Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues. |
0
|
score_threshold
|
Optional[float]
|
Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned. |
None
|
consistency
|
Optional[ReadConsistency]
|
Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all queried replicas - 'majority' - query all replicas, but return values present in the majority of replicas - 'quorum' - query the majority of replicas, return values present in all of them - 'all' - query all replicas, and return values present in all replicas |
None
|
**kwargs
|
Any
|
Any other named arguments to pass through to QdrantClient.search() |
{}
|
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents most similar to the query. |
asimilarity_search_by_vector
async
¶
asimilarity_search_by_vector(
embedding: list[float],
k: int = 4,
filter: Optional[MetadataFilter] = None,
search_params: Optional[SearchParams] = None,
offset: int = 0,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = None,
**kwargs: Any
) -> list[Document]
Return docs most similar to embedding vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embedding
|
list[float]
|
Embedding vector to look up documents similar to. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
filter
|
Optional[MetadataFilter]
|
Filter by metadata. Defaults to None. |
None
|
search_params
|
Optional[SearchParams]
|
Additional search params |
None
|
offset
|
int
|
Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues. |
0
|
score_threshold
|
Optional[float]
|
Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned. |
None
|
consistency
|
Optional[ReadConsistency]
|
Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all queried replicas - 'majority' - query all replicas, but return values present in the majority of replicas - 'quorum' - query the majority of replicas, return values present in all of them - 'all' - query all replicas, and return values present in all replicas |
None
|
**kwargs
|
Any
|
Any other named arguments to pass through to AsyncQdrantClient.Search(). |
{}
|
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents most similar to the query. |
similarity_search_with_score_by_vector
¶
similarity_search_with_score_by_vector(
embedding: list[float],
k: int = 4,
filter: Optional[MetadataFilter] = None,
search_params: Optional[SearchParams] = None,
offset: int = 0,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = None,
**kwargs: Any
) -> list[tuple[Document, float]]
Return docs most similar to embedding vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embedding
|
list[float]
|
Embedding vector to look up documents similar to. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
filter
|
Optional[MetadataFilter]
|
Filter by metadata. Defaults to None. |
None
|
search_params
|
Optional[SearchParams]
|
Additional search params |
None
|
offset
|
int
|
Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues. |
0
|
score_threshold
|
Optional[float]
|
Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned. |
None
|
consistency
|
Optional[ReadConsistency]
|
Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all queried replicas - 'majority' - query all replicas, but return values present in the majority of replicas - 'quorum' - query the majority of replicas, return values present in all of them - 'all' - query all replicas, and return values present in all replicas |
None
|
**kwargs
|
Any
|
Any other named arguments to pass through to QdrantClient.search() |
{}
|
Returns:
Type | 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: Optional[MetadataFilter] = None,
search_params: Optional[SearchParams] = None,
offset: int = 0,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = None,
**kwargs: Any
) -> list[tuple[Document, float]]
Return docs most similar to embedding vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embedding
|
list[float]
|
Embedding vector to look up documents similar to. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
filter
|
Optional[MetadataFilter]
|
Filter by metadata. Defaults to None. |
None
|
search_params
|
Optional[SearchParams]
|
Additional search params |
None
|
offset
|
int
|
Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues. |
0
|
score_threshold
|
Optional[float]
|
Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned. |
None
|
consistency
|
Optional[ReadConsistency]
|
Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all queried replicas - 'majority' - query all replicas, but return values present in the majority of replicas - 'quorum' - query the majority of replicas, return values present in all of them - 'all' - query all replicas, and return values present in all replicas |
None
|
**kwargs
|
Any
|
Any other named arguments to pass through to AsyncQdrantClient.Search(). |
{}
|
Returns:
Type | 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: Optional[MetadataFilter] = None,
search_params: Optional[SearchParams] = None,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = 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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
Text to look up documents similar to. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
fetch_k
|
int
|
Number of Documents to fetch to pass to MMR algorithm. Defaults to 20. |
20
|
lambda_mult
|
float
|
Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. |
0.5
|
filter
|
Optional[MetadataFilter]
|
Filter by metadata. Defaults to None. |
None
|
search_params
|
Optional[SearchParams]
|
Additional search params |
None
|
score_threshold
|
Optional[float]
|
Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned. |
None
|
consistency
|
Optional[ReadConsistency]
|
Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all queried replicas - 'majority' - query all replicas, but return values present in the majority of replicas - 'quorum' - query the majority of replicas, return values present in all of them - 'all' - query all replicas, and return values present in all replicas |
None
|
**kwargs
|
Any
|
Any other named arguments to pass through to QdrantClient.search() |
{}
|
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents selected by maximal marginal relevance. |
amax_marginal_relevance_search
async
¶
amax_marginal_relevance_search(
query: str,
k: int = 4,
fetch_k: int = 20,
lambda_mult: float = 0.5,
filter: Optional[MetadataFilter] = None,
search_params: Optional[SearchParams] = None,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = 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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
Text to look up documents similar to. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
fetch_k
|
int
|
Number of Documents to fetch to pass to MMR algorithm. Defaults to 20. |
20
|
lambda_mult
|
float
|
Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. |
0.5
|
filter
|
Optional[MetadataFilter]
|
Filter by metadata. Defaults to None. |
None
|
search_params
|
Optional[SearchParams]
|
Additional search params |
None
|
score_threshold
|
Optional[float]
|
Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned. |
None
|
consistency
|
Optional[ReadConsistency]
|
Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all queried replicas - 'majority' - query all replicas, but return values present in the majority of replicas - 'quorum' - query the majority of replicas, return values present in all of them - 'all' - query all replicas, and return values present in all replicas |
None
|
**kwargs
|
Any
|
Any other named arguments to pass through to AsyncQdrantClient.Search(). |
{}
|
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents 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: Optional[MetadataFilter] = None,
search_params: Optional[SearchParams] = None,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = 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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embedding
|
list[float]
|
Embedding to look up documents similar to. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
fetch_k
|
int
|
Number of Documents to fetch to pass to MMR algorithm. |
20
|
lambda_mult
|
float
|
Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. |
0.5
|
filter
|
Optional[MetadataFilter]
|
Filter by metadata. Defaults to None. |
None
|
search_params
|
Optional[SearchParams]
|
Additional search params |
None
|
score_threshold
|
Optional[float]
|
Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned. |
None
|
consistency
|
Optional[ReadConsistency]
|
Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all queried replicas - 'majority' - query all replicas, but return values present in the majority of replicas - 'quorum' - query the majority of replicas, return values present in all of them - 'all' - query all replicas, and return values present in all replicas |
None
|
**kwargs
|
Any
|
Any other named arguments to pass through to QdrantClient.search() |
{}
|
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents 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: Optional[MetadataFilter] = None,
search_params: Optional[SearchParams] = None,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = 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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embedding
|
list[float]
|
Embedding vector to look up documents similar to. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
fetch_k
|
int
|
Number of Documents to fetch to pass to MMR algorithm. Defaults to 20. |
20
|
lambda_mult
|
float
|
Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. |
0.5
|
filter
|
Optional[MetadataFilter]
|
Filter by metadata. Defaults to None. |
None
|
search_params
|
Optional[SearchParams]
|
Additional search params |
None
|
score_threshold
|
Optional[float]
|
Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned. |
None
|
consistency
|
Optional[ReadConsistency]
|
Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all queried replicas - 'majority' - query all replicas, but return values present in the majority of replicas - 'quorum' - query the majority of replicas, return values present in all of them - 'all' - query all replicas, and return values present in all replicas |
None
|
**kwargs
|
Any
|
Any other named arguments to pass through to AsyncQdrantClient.Search(). |
{}
|
Returns:
Type | Description |
---|---|
list[Document]
|
List of Documents selected by maximal marginal relevance and distance for |
list[Document]
|
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: Optional[MetadataFilter] = None,
search_params: Optional[SearchParams] = None,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = 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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embedding
|
list[float]
|
Embedding vector to look up documents similar to. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
fetch_k
|
int
|
Number of Documents to fetch to pass to MMR algorithm. Defaults to 20. |
20
|
lambda_mult
|
float
|
Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. |
0.5
|
filter
|
Optional[MetadataFilter]
|
Filter by metadata. Defaults to None. |
None
|
search_params
|
Optional[SearchParams]
|
Additional search params |
None
|
score_threshold
|
Optional[float]
|
Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned. |
None
|
consistency
|
Optional[ReadConsistency]
|
Read consistency of the search. Defines how many replicas should be queried before returning the result. Values: - int - number of replicas to query, values should present in all queried replicas - 'majority' - query all replicas, but return values present in the majority of replicas - 'quorum' - query the majority of replicas, return values present in all of them - 'all' - query all replicas, and return values present in all replicas |
None
|
**kwargs
|
Any
|
Any other named arguments to pass through to QdrantClient.search() |
{}
|
Returns:
Type | Description |
---|---|
list[tuple[Document, float]]
|
List of Documents selected by maximal marginal relevance and distance for |
list[tuple[Document, float]]
|
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: Optional[MetadataFilter] = None,
search_params: Optional[SearchParams] = None,
score_threshold: Optional[float] = None,
consistency: Optional[ReadConsistency] = 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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embedding
|
list[float]
|
Embedding vector to look up documents similar to. |
required |
k
|
int
|
Number of Documents to return. Defaults to 4. |
4
|
fetch_k
|
int
|
Number of Documents to fetch to pass to MMR algorithm. Defaults to 20. |
20
|
lambda_mult
|
float
|
Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5. |
0.5
|
filter
|
Optional[MetadataFilter]
|
Filter by metadata. Defaults to None. |
None
|
search_params
|
Optional[SearchParams]
|
Additional search params. |
None
|
score_threshold
|
Optional[float]
|
Define a minimal score threshold for the result. |
None
|
consistency
|
Optional[ReadConsistency]
|
Read consistency of the search. |
None
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Returns:
Type | Description |
---|---|
list[tuple[Document, float]]
|
List of Documents selected by maximal marginal relevance and distance for |
list[tuple[Document, float]]
|
each. |
delete
¶
adelete
async
¶
from_texts
classmethod
¶
from_texts(
texts: list[str],
embedding: Embeddings,
metadatas: Optional[list[dict]] = None,
ids: Optional[Sequence[str]] = None,
location: Optional[str] = None,
url: Optional[str] = None,
port: Optional[int] = 6333,
grpc_port: int = 6334,
prefer_grpc: bool = False,
https: Optional[bool] = None,
api_key: Optional[str] = None,
prefix: Optional[str] = None,
timeout: Optional[int] = None,
host: Optional[str] = None,
path: Optional[str] = None,
collection_name: Optional[str] = None,
distance_func: str = "Cosine",
content_payload_key: str = CONTENT_KEY,
metadata_payload_key: str = METADATA_KEY,
vector_name: Optional[str] = VECTOR_NAME,
batch_size: int = 64,
shard_number: Optional[int] = None,
replication_factor: Optional[int] = None,
write_consistency_factor: Optional[int] = None,
on_disk_payload: Optional[bool] = None,
hnsw_config: Optional[HnswConfigDiff] = None,
optimizers_config: Optional[
OptimizersConfigDiff
] = None,
wal_config: Optional[WalConfigDiff] = None,
quantization_config: Optional[
QuantizationConfig
] = None,
init_from: Optional[InitFrom] = None,
on_disk: Optional[bool] = None,
force_recreate: bool = False,
**kwargs: Any
) -> Qdrant
Construct Qdrant wrapper from a list of texts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
texts
|
list[str]
|
A list of texts to be indexed in Qdrant. |
required |
embedding
|
Embeddings
|
A subclass of |
required |
metadatas
|
Optional[list[dict]]
|
An optional list of metadata. If provided it has to be of the same length as a list of texts. |
None
|
ids
|
Optional[Sequence[str]]
|
Optional list of ids to associate with the texts. Ids have to be uuid-like strings. |
None
|
location
|
Optional[str]
|
If ':memory:' - use in-memory Qdrant instance.
If |
None
|
url
|
Optional[str]
|
either host or str of "Optional[scheme], host, Optional[port],
Optional[prefix]". Default: |
None
|
port
|
Optional[int]
|
Port of the REST API interface. Default: 6333 |
6333
|
grpc_port
|
int
|
Port of the gRPC interface. Default: 6334 |
6334
|
prefer_grpc
|
bool
|
If true - use gPRC interface whenever possible in custom methods. Default: False |
False
|
https
|
Optional[bool]
|
If true - use HTTPS(SSL) protocol. Default: None |
None
|
api_key
|
Optional[str]
|
|
None
|
prefix
|
Optional[str]
|
If not None - add prefix to the REST URL path. Example: service/v1 will result in http://localhost:6333/service/v1/{qdrant-endpoint} for REST API. Default: None |
None
|
timeout
|
Optional[int]
|
Timeout for REST and gRPC API requests. Default: 5.0 seconds for REST and unlimited for gRPC |
None
|
host
|
Optional[str]
|
Host name of Qdrant service. If url and host are None, set to 'localhost'. Default: None |
None
|
path
|
Optional[str]
|
Path in which the vectors will be stored while using local mode. Default: None |
None
|
collection_name
|
Optional[str]
|
Name of the Qdrant collection to be used. If not provided, it will be created randomly. Default: None |
None
|
distance_func
|
str
|
Distance function. One of: "Cosine" / "Euclid" / "Dot". Default: "Cosine" |
'Cosine'
|
content_payload_key
|
str
|
A payload key used to store the content of the document. Default: "page_content" |
CONTENT_KEY
|
metadata_payload_key
|
str
|
A payload key used to store the metadata of the document. Default: "metadata" |
METADATA_KEY
|
vector_name
|
Optional[str]
|
Name of the vector to be used internally in Qdrant. Default: None |
VECTOR_NAME
|
batch_size
|
int
|
How many vectors upload per-request. Default: 64 |
64
|
shard_number
|
Optional[int]
|
Number of shards in collection. Default is 1, minimum is 1. |
None
|
replication_factor
|
Optional[int]
|
Replication factor for collection. Default is 1, minimum is 1. Defines how many copies of each shard will be created. Have effect only in distributed mode. |
None
|
write_consistency_factor
|
Optional[int]
|
Write consistency factor for collection. Default is 1, minimum is 1. Defines how many replicas should apply the operation for us to consider it successful. Increasing this number will make the collection more resilient to inconsistencies, but will also make it fail if not enough replicas are available. Does not have any performance impact. Have effect only in distributed mode. |
None
|
on_disk_payload
|
Optional[bool]
|
If true - point`s payload will not be stored in memory. It will be read from the disk every time it is requested. This setting saves RAM by (slightly) increasing the response time. Note: those payload values that are involved in filtering and are indexed - remain in RAM. |
None
|
hnsw_config
|
Optional[HnswConfigDiff]
|
Params for HNSW index |
None
|
optimizers_config
|
Optional[OptimizersConfigDiff]
|
Params for optimizer |
None
|
wal_config
|
Optional[WalConfigDiff]
|
Params for Write-Ahead-Log |
None
|
quantization_config
|
Optional[QuantizationConfig]
|
Params for quantization, if None - quantization will be disabled |
None
|
init_from
|
Optional[InitFrom]
|
Use data stored in another collection to initialize this collection |
None
|
on_disk
|
Optional[bool]
|
If true - vectors will be stored on disk, reducing memory usage. |
None
|
force_recreate
|
bool
|
Force recreating the collection |
False
|
**kwargs
|
Any
|
Additional arguments passed directly into REST client initialization |
{}
|
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.
Example
.. code-block:: python
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: Optional[str] = None,
collection_name: Optional[str] = None,
location: Optional[str] = None,
url: Optional[str] = None,
port: Optional[int] = 6333,
grpc_port: int = 6334,
prefer_grpc: bool = False,
https: Optional[bool] = None,
api_key: Optional[str] = None,
prefix: Optional[str] = None,
timeout: Optional[int] = None,
host: Optional[str] = None,
content_payload_key: str = CONTENT_KEY,
metadata_payload_key: str = METADATA_KEY,
distance_strategy: str = "COSINE",
vector_name: Optional[str] = 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: Optional[list[dict]] = None,
ids: Optional[Sequence[str]] = None,
location: Optional[str] = None,
url: Optional[str] = None,
port: Optional[int] = 6333,
grpc_port: int = 6334,
prefer_grpc: bool = False,
https: Optional[bool] = None,
api_key: Optional[str] = None,
prefix: Optional[str] = None,
timeout: Optional[int] = None,
host: Optional[str] = None,
path: Optional[str] = None,
collection_name: Optional[str] = None,
distance_func: str = "Cosine",
content_payload_key: str = CONTENT_KEY,
metadata_payload_key: str = METADATA_KEY,
vector_name: Optional[str] = VECTOR_NAME,
batch_size: int = 64,
shard_number: Optional[int] = None,
replication_factor: Optional[int] = None,
write_consistency_factor: Optional[int] = None,
on_disk_payload: Optional[bool] = None,
hnsw_config: Optional[HnswConfigDiff] = None,
optimizers_config: Optional[
OptimizersConfigDiff
] = None,
wal_config: Optional[WalConfigDiff] = None,
quantization_config: Optional[
QuantizationConfig
] = None,
init_from: Optional[InitFrom] = None,
on_disk: Optional[bool] = None,
force_recreate: bool = False,
**kwargs: Any
) -> Qdrant
Construct Qdrant wrapper from a list of texts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
texts
|
list[str]
|
A list of texts to be indexed in Qdrant. |
required |
embedding
|
Embeddings
|
A subclass of |
required |
metadatas
|
Optional[list[dict]]
|
An optional list of metadata. If provided it has to be of the same length as a list of texts. |
None
|
ids
|
Optional[Sequence[str]]
|
Optional list of ids to associate with the texts. Ids have to be uuid-like strings. |
None
|
location
|
Optional[str]
|
If ':memory:' - use in-memory Qdrant instance.
If |
None
|
url
|
Optional[str]
|
either host or str of "Optional[scheme], host, Optional[port],
Optional[prefix]". Default: |
None
|
port
|
Optional[int]
|
Port of the REST API interface. Default: 6333 |
6333
|
grpc_port
|
int
|
Port of the gRPC interface. Default: 6334 |
6334
|
prefer_grpc
|
bool
|
If true - use gPRC interface whenever possible in custom methods. Default: False |
False
|
https
|
Optional[bool]
|
If true - use HTTPS(SSL) protocol. Default: None |
None
|
api_key
|
Optional[str]
|
|
None
|
prefix
|
Optional[str]
|
If not None - add prefix to the REST URL path. Example: service/v1 will result in http://localhost:6333/service/v1/{qdrant-endpoint} for REST API. Default: None |
None
|
timeout
|
Optional[int]
|
Timeout for REST and gRPC API requests. Default: 5.0 seconds for REST and unlimited for gRPC |
None
|
host
|
Optional[str]
|
Host name of Qdrant service. If url and host are None, set to 'localhost'. Default: None |
None
|
path
|
Optional[str]
|
Path in which the vectors will be stored while using local mode. Default: None |
None
|
collection_name
|
Optional[str]
|
Name of the Qdrant collection to be used. If not provided, it will be created randomly. Default: None |
None
|
distance_func
|
str
|
Distance function. One of: "Cosine" / "Euclid" / "Dot". Default: "Cosine" |
'Cosine'
|
content_payload_key
|
str
|
A payload key used to store the content of the document. Default: "page_content" |
CONTENT_KEY
|
metadata_payload_key
|
str
|
A payload key used to store the metadata of the document. Default: "metadata" |
METADATA_KEY
|
vector_name
|
Optional[str]
|
Name of the vector to be used internally in Qdrant. Default: None |
VECTOR_NAME
|
batch_size
|
int
|
How many vectors upload per-request. Default: 64 |
64
|
shard_number
|
Optional[int]
|
Number of shards in collection. Default is 1, minimum is 1. |
None
|
replication_factor
|
Optional[int]
|
Replication factor for collection. Default is 1, minimum is 1. Defines how many copies of each shard will be created. Have effect only in distributed mode. |
None
|
write_consistency_factor
|
Optional[int]
|
Write consistency factor for collection. Default is 1, minimum is 1. Defines how many replicas should apply the operation for us to consider it successful. Increasing this number will make the collection more resilient to inconsistencies, but will also make it fail if not enough replicas are available. Does not have any performance impact. Have effect only in distributed mode. |
None
|
on_disk_payload
|
Optional[bool]
|
If true - point`s payload will not be stored in memory. It will be read from the disk every time it is requested. This setting saves RAM by (slightly) increasing the response time. Note: those payload values that are involved in filtering and are indexed - remain in RAM. |
None
|
hnsw_config
|
Optional[HnswConfigDiff]
|
Params for HNSW index |
None
|
optimizers_config
|
Optional[OptimizersConfigDiff]
|
Params for optimizer |
None
|
wal_config
|
Optional[WalConfigDiff]
|
Params for Write-Ahead-Log |
None
|
quantization_config
|
Optional[QuantizationConfig]
|
Params for quantization, if None - quantization will be disabled |
None
|
init_from
|
Optional[InitFrom]
|
Use data stored in another collection to initialize this collection |
None
|
on_disk
|
Optional[bool]
|
If true - point`s payload will not be stored in memory. It will be read from the disk every time it is requested. This setting saves RAM by (slightly) increasing the response time. Note: those payload values that are involved in filtering and are indexed - remain in RAM. |
None
|
force_recreate
|
bool
|
Force recreating the collection |
False
|
**kwargs
|
Any
|
Additional arguments passed directly into REST client initialization |
{}
|
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.
Example
.. code-block:: python
from langchain_qdrant import Qdrant
from langchain_openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
qdrant = await Qdrant.afrom_texts(texts, embeddings, "localhost")