mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
style: .. code-block:: admonition translations (#33400)
biiiiiiiiiiiiiiiigggggggg pass
This commit is contained in:
@@ -42,9 +42,9 @@ class QdrantVectorStore(VectorStore):
|
||||
Setup:
|
||||
Install `langchain-qdrant` package.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
pip install -qU langchain-qdrant
|
||||
```bash
|
||||
pip install -qU langchain-qdrant
|
||||
```
|
||||
|
||||
Key init args — indexing params:
|
||||
collection_name: str
|
||||
@@ -61,150 +61,148 @@ class QdrantVectorStore(VectorStore):
|
||||
Retrieval mode to use.
|
||||
|
||||
Instantiate:
|
||||
.. code-block:: python
|
||||
```python
|
||||
from langchain_qdrant import QdrantVectorStore
|
||||
from qdrant_client import QdrantClient
|
||||
from qdrant_client.http.models import Distance, VectorParams
|
||||
from langchain_openai import OpenAIEmbeddings
|
||||
|
||||
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 = QdrantClient(":memory:")
|
||||
client.create_collection(
|
||||
collection_name="demo_collection",
|
||||
vectors_config=VectorParams(size=1536, distance=Distance.COSINE),
|
||||
)
|
||||
|
||||
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(),
|
||||
)
|
||||
vector_store = QdrantVectorStore(
|
||||
client=client,
|
||||
collection_name="demo_collection",
|
||||
embedding=OpenAIEmbeddings(),
|
||||
)
|
||||
```
|
||||
|
||||
Add Documents:
|
||||
.. code-block:: python
|
||||
```python
|
||||
from langchain_core.documents import Document
|
||||
from uuid import uuid4
|
||||
|
||||
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 :(")
|
||||
|
||||
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)
|
||||
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]])
|
||||
```python
|
||||
vector_store.delete(ids=[ids[-1]])
|
||||
```
|
||||
|
||||
Search:
|
||||
.. code-block:: python
|
||||
```python
|
||||
results = vector_store.similarity_search(
|
||||
query="thud",
|
||||
k=1,
|
||||
)
|
||||
for doc in results:
|
||||
print(f"* {doc.page_content} [{doc.metadata}]")
|
||||
```
|
||||
|
||||
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",
|
||||
}
|
||||
]
|
||||
```python
|
||||
*thud[
|
||||
{
|
||||
"bar": "baz",
|
||||
"_id": "0d706099-6dd9-412a-9df6-a71043e020de",
|
||||
"_collection_name": "demo_collection",
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
Search with filter:
|
||||
.. code-block:: python
|
||||
```python
|
||||
from qdrant_client.http import models
|
||||
|
||||
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}]")
|
||||
```
|
||||
|
||||
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}]")
|
||||
```python
|
||||
*thud[
|
||||
{
|
||||
"bar": "baz",
|
||||
"_id": "0d706099-6dd9-412a-9df6-a71043e020de",
|
||||
"_collection_name": "demo_collection",
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
.. code-block:: python
|
||||
Search with score:
|
||||
```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}]")
|
||||
```
|
||||
|
||||
*thud[
|
||||
{
|
||||
```python
|
||||
* [SIM=0.832268] foo [{'baz': 'bar', '_id': '44ec7094-b061-45ac-8fbf-014b0f18e8aa', '_collection_name': 'demo_collection'}]
|
||||
```
|
||||
|
||||
Async:
|
||||
```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}]")
|
||||
```
|
||||
|
||||
```python
|
||||
* [SIM=0.832268] foo [{'baz': 'bar', '_id': '44ec7094-b061-45ac-8fbf-014b0f18e8aa', '_collection_name': 'demo_collection'}]
|
||||
```
|
||||
|
||||
Use as Retriever:
|
||||
```python
|
||||
retriever = vector_store.as_retriever(
|
||||
search_type="mmr",
|
||||
search_kwargs={"k": 1, "fetch_k": 2, "lambda_mult": 0.5},
|
||||
)
|
||||
retriever.invoke("thud")
|
||||
```
|
||||
|
||||
```python
|
||||
[
|
||||
Document(
|
||||
metadata={
|
||||
"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},
|
||||
},
|
||||
page_content="thud",
|
||||
)
|
||||
retriever.invoke("thud")
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
[
|
||||
Document(
|
||||
metadata={
|
||||
"bar": "baz",
|
||||
"_id": "0d706099-6dd9-412a-9df6-a71043e020de",
|
||||
"_collection_name": "demo_collection",
|
||||
},
|
||||
page_content="thud",
|
||||
)
|
||||
]
|
||||
|
||||
]
|
||||
```
|
||||
""" # noqa: E501
|
||||
|
||||
CONTENT_KEY: str = "page_content"
|
||||
@@ -229,16 +227,15 @@ class QdrantVectorStore(VectorStore):
|
||||
) -> 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(),
|
||||
)
|
||||
|
||||
```python
|
||||
qdrant = Qdrant(
|
||||
client=client,
|
||||
collection_name="my-collection",
|
||||
embedding=OpenAIEmbeddings(),
|
||||
retrieval_mode=RetrievalMode.HYBRID,
|
||||
sparse_embedding=FastEmbedSparse(),
|
||||
)
|
||||
```
|
||||
"""
|
||||
if validate_embeddings:
|
||||
self._validate_embeddings(retrieval_mode, embedding, sparse_embedding)
|
||||
@@ -385,14 +382,13 @@ class QdrantVectorStore(VectorStore):
|
||||
|
||||
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")
|
||||
```python
|
||||
from langchain_qdrant import Qdrant
|
||||
from langchain_openai import OpenAIEmbeddings
|
||||
|
||||
embeddings = OpenAIEmbeddings()
|
||||
qdrant = Qdrant.from_texts(texts, embeddings, url="http://localhost:6333")
|
||||
```
|
||||
"""
|
||||
if sparse_vector_params is None:
|
||||
sparse_vector_params = {}
|
||||
|
||||
Reference in New Issue
Block a user