当前位置:   article > 正文

qdrant

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
  • 1

docker

First, download the latest Qdrant image from Dockerhub:

docker pull qdrant/qdrant
  • 1

Then, run the service:

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

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)
  • 1
  • 2
  • 3

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

从本地初始化

client = QdrantClient(path="path/to/db") 
# 或
client = QdrantClient(":memory:")
  • 1
  • 2
  • 3

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),
)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

Response:

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


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)
  • 1
  • 2
  • 3
  • 4
  • 5

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)
  • 1
  • 2
  • 3

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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

Response:

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

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(三)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/381930
推荐阅读
相关标签
  

闽ICP备14008679号