qdrant

在这里插入图片描述


一、关于 qdrant

Qdrant - High-performance, massive-scale Vector Database for the next generation of AI.

qdrant (read: quadrant)



Features


Filtering and Payload

Qdrant can attach any JSON payloads to vectors, allowing for both the storage and filtering of data based on the values in these payloads. Payload supports a wide range of data types and query conditions, including keyword matching, full-text filtering, numerical ranges, geo-locations, and more.

Filtering conditions can be combined in various ways, including should, must, and must_not clauses, ensuring that you can implement any desired business logic on top of similarity matching.


Hybrid Search with Sparse Vectors

To address the limitations of vector embeddings when searching for specific keywords, Qdrant introduces support for sparse vectors in addition to the regular dense ones.

Sparse vectors can be viewed as an generalisation of BM25 or TF-IDF ranking. They enable you to harness the capabilities of transformer-based neural networks to weigh individual tokens effectively.


Vector Quantization and On-Disk Storage

Qdrant provides multiple options to make vector search cheaper and more resource-efficient. Built-in vector quantization reduces RAM usage by up to 97% and dynamically manages the trade-off between search speed and precision.


Distributed Deployment

Qdrant offers comprehensive horizontal scaling support through two key mechanisms:

  1. Size expansion via sharding and throughput enhancement via replication
  2. Zero-downtime rolling updates and seamless dynamic scaling of the collections

Highlighted Features
  • Query Planning and Payload Indexes - leverages stored payload information to optimize query execution strategy.
  • SIMD Hardware Acceleration - utilizes modern CPU x86-x64 and Neon architectures to deliver better performance.
  • Async I/O - uses io_uring to maximize disk throughput utilization even on a network-attached storage.
  • Write-Ahead Logging - ensures data persistence with update confirmation, even during power outages.

有三种方式使用 Qdrant

  1. Run a Docker image if you don’t have a Python development environment. Setup a local Qdrant server and storage in a few moments.
  2. Get the Python client if you’re familiar with Python. Just pip install qdrant-client. The client also supports an in-memory database.
  3. Spin up a Qdrant Cloud cluster: the recommended method to run Qdrant in production.
    Read Quickstart to setup your first instance.

推荐 Workflow

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传


Integrations

Examples and/or documentation of Qdrant integrations:


二、快速上手

https://qdrant.tech/documentation/quick-start/


1、下载和运行


安装 qdrant-client
pip install qdrant-client

docker

First, download the latest Qdrant image from Dockerhub:

docker pull qdrant/qdrant

Then, run the service:

docker run -p 6333:6333 -p 6334:6334 \
    -v $(pwd)/qdrant_storage:/qdrant/storage:z \
    qdrant/qdrant

Under the default configuration all data will be stored in the ./qdrant_storage directory.

This will also be the only directory that both the Container and the host machine can both see.

Qdrant is now accessible:


2、初始化 client

from qdrant_client import QdrantClient

client = QdrantClient("localhost", port=6333)

client = QdrantClient(url="http://localhost:6333")

从本地初始化

client = QdrantClient(path="path/to/db") 
# 或
client = QdrantClient(":memory:")

By default, Qdrant starts with no encryption or authentication .

This means anyone with network access to your machine can access your Qdrant container instance.

Please read Security carefully for details on how to secure your instance.


3、创建 collection

You will be storing all of your vector data in a Qdrant collection. Let’s call it test_collection.

This collection will be using a dot product distance metric to compare vectors.

from qdrant_client.http.models import Distance, VectorParams

client.create_collection(
    collection_name="test_collection",
    vectors_config=VectorParams(size=4, distance=Distance.DOT),
)

TypeScript, Rust examples use async/await syntax, so should be used in an async block.

Java examples are enclosed within a try/catch block.


4、添加向量

Let’s now add a few vectors with a payload. Payloads are other data you want to associate with the vector:

from qdrant_client.http.models import PointStruct

operation_info = client.upsert(
    collection_name="test_collection",
    wait=True,
    points=[
        PointStruct(id=1, vector=[0.05, 0.61, 0.76, 0.74], payload={"city": "Berlin"}),
        PointStruct(id=2, vector=[0.19, 0.81, 0.75, 0.11], payload={"city": "London"}),
        PointStruct(id=3, vector=[0.36, 0.55, 0.47, 0.94], payload={"city": "Moscow"}),
        PointStruct(id=4, vector=[0.18, 0.01, 0.85, 0.80], payload={"city": "New York"}),
        PointStruct(id=5, vector=[0.24, 0.18, 0.22, 0.44], payload={"city": "Beijing"}),
        PointStruct(id=6, vector=[0.35, 0.08, 0.11, 0.44], payload={"city": "Mumbai"}),
    ],
)

print(operation_info)

Response:

operation_id=0 status=<UpdateStatus.COMPLETED: 'completed'>


5、运行 query

Let’s ask a basic question - Which of our stored vectors are most similar to the query vector [0.2, 0.1, 0.9, 0.7]?

search_result = client.search(
    collection_name="test_collection", query_vector=[0.2, 0.1, 0.9, 0.7], limit=3
)

print(search_result)

Response:

ScoredPoint(id=4, version=0, score=1.362, payload={"city": "New York"}, vector=None),
ScoredPoint(id=1, version=0, score=1.273, payload={"city": "Berlin"}, vector=None),
ScoredPoint(id=3, version=0, score=1.208, payload={"city": "Moscow"}, vector=None)

The results are returned in decreasing similarity order.

Note that payload and vector data is missing in these results by default.

See payload and vector in the result on how to enable it.


6、添加 filter

We can narrow down the results further by filtering by payload.

Let’s find the closest results that include “London”.

from qdrant_client.http.models import Filter, FieldCondition, MatchValue

search_result = client.search(
    collection_name="test_collection",
    query_vector=[0.2, 0.1, 0.9, 0.7],
    query_filter=Filter(
        must=[FieldCondition(key="city", match=MatchValue(value="London"))]
    ),
    with_payload=True,
    limit=3,
)

print(search_result)

Response:

ScoredPoint(id=2, version=0, score=0.871, payload={"city": "London"}, vector=None)

To make filtered search fast on real datasets, we highly recommend to create payload indexes!

You have just conducted vector search. You loaded vectors into a database and queried the database with a vector of your own.

Qdrant found the closest results and presented you with a similarity score.



三、Qdrant Examples

This repo contains a collection of tutorials, demos, and how-to guides on how to use Qdrant and adjacent technologies.

ExampleDescriptionTechnologies
Huggingface Spaces with QdrantHost a public demo quickly for your similarity app with HF Spaces and Qdrant CloudHF Spaces, CLIP, semantic image search
QA which is always updated: Recency and Cohere using Llama IndexNotebook which demonstrates how you can keep your QA system always use updated informationLlama Index, OpenAI Embeddings, Cohere Reranker
Qdrant 101 - Getting StartedIntroduction to semantic search and the recommendation API of QdrantNumPy and Faker
Qdrant 101 - Text DataIntroduction to the intersection of Vector Databases and Natural Language Processingtransformers, datasets, GPT-2, Sentence Transformers, PyTorch
Qdrant 101 - Audio DataIntroduction to audio data, audio embeddings, and music recommendation systemstransformers, librosa, openl3, panns_inference, streamlit, datasets, PyTorch
Ecommerce - reverse image searchNotebook demonstrating how to implement a reverse image search for ecommerceCLIP, semantic image search, Sentence-Transformers
Serverless Semantic SearchGet a semantic page search without setting up a serverRust, AWS lambda, Cohere embedding
Basic RAGBasic RAG pipeline with Qdrant and OpenAI SDKsOpenAI, Qdrant, FastEmbed
Step-back prompting in Langchain RAGStep-back prompting for RAG, implemented in LangchainOpenAI, Qdrant, Cohere, Langchain
Collaborative Filtering and MovieLensA notebook demonstrating how to build a collaborative filtering system using QdrantSparse Vectors, Qdrant
Use semantic search to navigate your codebaseImplement semantic search application for code search taskQdrant, Python, sentence-transformers, Jina

2024-03-27(三)

### Qdrant 向量数据库使用指南 #### 导入Qdrant向量存储库 为了能够操作Qdrant向量数据库,需要通过特定的Python包来实现这一功能。这可以通过下面给出的语句完成: ```python from langchain_qdrant import QdrantVectorStore ``` 此命令允许开发者访问`QdrantVectorStore`类以便进一步的操作[^1]。 #### 数据准备与环境设置 对于希望利用LlamaIndex项目中的资源作为测试数据集的情况,建议按照官方指引先行克隆该项目至本地环境中,并确保所需的数据文件位于指定路径下(例如`paul_graham_essay`目录)。这样做的好处是可以方便快捷地获取到高质量的样例文档用于实验目的[^2]。 #### 安装配置过程概述 安装并配置好Qdrant服务端之后,就可以着手于客户端侧的应用开发工作了。通常来说,这意味着要在应用程序里集成相应的SDK或API接口来进行后续的任务处理。上述提到过的`langchain_qdrant`模块即是为此而设计的一个工具选项之一[^3]。 #### 示例代码片段展示如何连接到远程实例 一旦完成了必要的前期准备工作,便可以编写简单的脚本来验证整个流程是否顺畅无阻。这里提供了一个基本的例子说明怎样建立同远端服务器之间的链接关系: ```python import qdrant_client as qc client = qc.QdrantClient( url="http://localhost:6333", # 替换成实际的服务地址 ) vector_store = QdrantVectorStore(client=client, collection_name="my_collection") ``` 这段程序展示了初始化一个Qdrant客户端对象以及创建关联矢量储存的具体方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程乐园

请我喝杯伯爵奶茶~!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值