由 deepset 维护

集成:Qdrant
将 Qdrant 向量数据库与 Haystack 一起使用
由 deepset 集成的 Qdrant 向量数据库与 Haystack。
该库最终允许将 Qdrant 用作文档存储,并且可以就地替换任何其他向量嵌入存储。因此,您应该期望通过将提供程序更改为 QdrantDocumentStore
来使任何类型的应用程序顺利运行。
安装
qdrant-haystack
可以像其他 Python 库一样安装,使用 pip 或 poetry
pip install qdrant-haystack
poetry add qdrant-haystack
使用
安装后,您就可以开始像使用任何其他支持嵌入的存储一样使用 QdrantDocumentStore
了。
from haystack_integrations.document_stores.qdrant import QdrantDocumentStore
document_store = QdrantDocumentStore(
url="localhost",
index="Document",
embedding_dim=512,
recreate_index=False,
hnsw_config={"m": 16, "ef_construct": 64} # Optional
)
QdrantDocumentStore
接受的参数列表是对官方 Python Qdrant 客户端 中使用的参数的补充。
使用本地内存/磁盘持久化模式
Qdrant Python 客户端(从 1.1.1 版开始)支持本地内存/磁盘持久化模式。对于您不打算存储大量向量的任何测试场景和快速实验来说,这是一个不错的选择。在这种情况下,可能甚至不需要启动 Docker 容器。
本地模式也已在 qdrant-haystack
集成中实现。
内存存储
如果您想要一个瞬时存储,例如在 CI/CD 管道中运行的自动化测试中,使用 Qdrant 本地模式的内存存储可能是一个首选选项。只需在创建 QdrantDocumentStore
实例时,将 :memory:
作为第一个参数传递即可启用。
from haystack_integrations.document_stores.qdrant import QdrantDocumentStore
document_store = QdrantDocumentStore(
":memory:",
index="Document",
embedding_dim=512,
recreate_index=False,
hnsw_config={"m": 16, "ef_construct": 64} # Optional
)
磁盘存储
但是,如果您希望在应用程序的不同运行之间保留向量,最好使用磁盘存储并传递应该用于持久化数据的路径。
from haystack_integrations.document_stores.qdrant import QdrantDocumentStore
document_store = QdrantDocumentStore(
path="/home/qdrant/storage_local",
index="Document",
embedding_dim=512,
recreate_index=False,
hnsw_config={"m": 16, "ef_construct": 64} # Optional
)
连接到 Qdrant Cloud 集群
如果您不想管理自己的 Qdrant 实例,Qdrant Cloud 可能是更好的选择。
from haystack_integrations.document_stores.qdrant import QdrantDocumentStore
from haystack.utils import Secret
document_store = QdrantDocumentStore(
url="https://YOUR-CLUSTER-URL.aws.cloud.qdrant.io",
index="Document",
api_key=Secret.from_env_var("QDRANT_API_KEY"),
embedding_dim=512,
recreate_index=False,
)
本地实例和云集群在功能上没有区别。