• Stars
    star
    636
  • Rank 69,028 (Top 2 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 3 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python client for Qdrant vector search engine

Qdrant

Python Client library for the Qdrant vector search engine.

PyPI version OpenAPI Docs Apache 2.0 License Discord Roadmap 2023

Python Qdrant Client

Client library and SDK for the Qdrant vector search engine.

Library contains type definitions for all Qdrant API and allows to make both Sync and Async requests.

Client allows calls for all Qdrant API methods directly. It also provides some additional helper methods for frequently required operations, e.g. initial collection uploading.

See QuickStart for more details!

Installation

pip install qdrant-client

Features

  • Type hints for all API methods
  • Local mode - use same API without running server
  • REST and gRPC support
  • Minimal dependencies
  • Extensive Test Coverage

Local mode

Qdrant

Python client allows you to run same code in local mode without running Qdrant server.

Simply initialize client like this:

from qdrant_client import QdrantClient

client = QdrantClient(":memory:")
# or
client = QdrantClient(path="path/to/db")  # Persists changes to disk

Local mode is useful for development, prototyping and testing.

  • You can use it to run tests in your CI/CD pipeline.
  • Run it in Colab or Jupyter Notebook, no extra dependencies required. See an example
  • When you need to scale, simply switch to server mode.

Fast Embeddings + Simpler API

pip install qdrant-client[fastembed]

FastEmbed is a library for creating fast vector embeddings on CPU. It is based on ONNX Runtime and allows to run inference on CPU with GPU-like performance.

Qdrant Client can use FastEmbed to create embeddings and upload them to Qdrant. This allows to simplify API and make it more intuitive.

from qdrant_client import QdrantClient

# Initialize the client
client = QdrantClient(":memory:")  # or QdrantClient(path="path/to/db")

# Prepare your documents, metadata, and IDs
docs = ["Qdrant has Langchain integrations", "Qdrant also has Llama Index integrations"]
metadata = [
    {"source": "Langchain-docs"},
    {"source": "Linkedin-docs"},
]
ids = [42, 2]

# Use the new add method
client.add(
    collection_name="demo_collection",
    documents=docs,
    metadata=metadata,
    ids=ids
)

search_result = client.query(
    collection_name="demo_collection",
    query_text="This is a query document"
)
print(search_result)

Connect to Qdrant server

To connect to Qdrant server, simply specify host and port:

from qdrant_client import QdrantClient

client = QdrantClient(host="localhost", port=6333)
# or
client = QdrantClient(url="http://localhost:6333")

You can run Qdrant server locally with docker:

docker run -p 6333:6333 qdrant/qdrant:latest

See more launch options in Qdrant repository.

Connect to Qdrant cloud

You can register and use Qdrant Cloud to get a free tier account with 1GB RAM.

Once you have your cluster and API key, you can connect to it like this:

from qdrant_client import QdrantClient

qdrant_client = QdrantClient(
    url="https://xxxxxx-xxxxx-xxxxx-xxxx-xxxxxxxxx.us-east.aws.cloud.qdrant.io:6333",
    api_key="<your-api-key>",
)

Examples

Create a new collection

from qdrant_client.models import Distance, VectorParams

client.recreate_collection(
    collection_name="my_collection",
    vectors_config=VectorParams(size=100, distance=Distance.COSINE),
)

Insert vectors into a collection

import numpy as np
from qdrant_client.models import PointStruct

vectors = np.random.rand(100, 100)
client.upsert(
    collection_name="my_collection",
    points=[
        PointStruct(
            id=idx,
            vector=vector.tolist(),
            payload={"color": "red", "rand_number": idx % 10}
        )
        for idx, vector in enumerate(vectors)
    ]
)

Search for similar vectors

query_vector = np.random.rand(100)
hits = client.search(
    collection_name="my_collection",
    query_vector=query_vector,
    limit=5  # Return 5 closest points
)

Search for similar vectors with filtering condition

from qdrant_client.models import Filter, FieldCondition, Range

hits = client.search(
    collection_name="my_collection",
    query_vector=query_vector,
    query_filter=Filter(
        must=[  # These conditions are required for search results
            FieldCondition(
                key='rand_number',  # Condition based on values of `rand_number` field.
                range=Range(
                    gte=3  # Select only those results where `rand_number` >= 3
                )
            )
        ]
    ),
    limit=5  # Return 5 closest points
)

See more examples in our Documentation!

gRPC

To enable (typically, much faster) collection uploading with gRPC, use the following initialization:

from qdrant_client import QdrantClient

client = QdrantClient(host="localhost", grpc_port=6334, prefer_grpc=True)

Async client

Async methods are available in raw autogenerated clients. Usually, you don't need to use them directly, but if you need extra performance, you can access them directly.

Async gRPC

Example of using raw async gRPC client:

from qdrant_client import QdrantClient, grpc

client = QdrantClient(prefer_grpc=True, timeout=3.0)

grpc_collections = client.async_grpc_collections

res = await grpc_collections.List(grpc.ListCollectionsRequest(), timeout=1.0)

More examples can be found here.

Development

This project uses git hooks to run code formatters.

Install pre-commit with pip3 install pre-commit and set up hooks with pre-commit install.

pre-commit requires python>=3.8

More Repositories

1

qdrant

Qdrant - High-performance, massive-scale Vector Database for the next generation of AI. Also available in the cloud https://cloud.qdrant.io/
Rust
18,502
star
2

fastembed

Fast, Accurate, Lightweight Python library to make State of the Art Embedding
Python
916
star
3

quaterion

Blazing fast framework for fine-tuning similarity learning models
Python
627
star
4

awesome-metric-learning

😎 A curated list of awesome practical Metric Learning and its applications
441
star
5

vector-db-benchmark

Framework for benchmarking vector search engines
Python
231
star
6

qdrant-js

JavaScript/Typescript SDK for Qdrant Vector Database
TypeScript
204
star
7

rust-client

Rust client for Qdrant vector search engine
Rust
196
star
8

qdrant-web-ui

Self-hosted web UI for Qdrant
JavaScript
188
star
9

page-search

Neural search for web-sites, docs, articles - online!
Rust
123
star
10

go-client

Go client for Qdrant vector search engine
Go
120
star
11

qdrant_demo

Demo of the neural semantic search built with Qdrant
TypeScript
115
star
12

qdrant-helm

Go
82
star
13

examples

A collection of examples and tutorials for Qdrant vector search engine
Jupyter Notebook
79
star
14

qdrant-dotnet

Qdrant .Net SDK
C#
76
star
15

qdrant-spark

Qdrant's Apache Spark connector
Java
41
star
16

qdrant-haystack

An integration of Qdrant ANN vector database backend with Haystack
Python
39
star
17

ann-filtering-benchmark-datasets

Collection of datasets for benchmarking filtered vector similarity retrieval
Python
30
star
18

quaterion-models

The collection of bulding blocks building fine-tunable metric learning models
Python
30
star
19

demo-food-discovery

Source code of the food discovery demo built on top of Qdrant
TypeScript
28
star
20

goods_categorization_demo

Demo example of consumer goods categorization
Jupyter Notebook
25
star
21

qdrant-txtai

An integration of Qdrant ANN vector database backend with txtai
Python
23
star
22

java-client

Official Java client for Qdrant
Java
23
star
23

workshop-rag-optimization

Notebooks for RAG optimization workshop, using HackerNews data
Jupyter Notebook
20
star
24

wal

Write Ahead Logging for Rust
Rust
16
star
25

landing_page

Landing page for qdrant.tech
SCSS
14
star
26

bfb

*high-load* benchmarking tool
Rust
12
star
27

qdrant-rag-eval

This repo is the central repo for all the RAG Evaluation reference material and partner workshop
Jupyter Notebook
11
star
28

demo-cloud-faq

Demo of fine-tuning QA models for answering FAQ of cloud providers documentation
Python
10
star
29

benchmark

Collection of Qdrant benchmarks
Python
7
star
30

demo-code-search

Python
7
star
31

qdrant-markdown-indexer

Simple pipeline to index markdown files into Qdrant using OpenAI embeddings
Python
6
star
32

autocomplete-openapi

Autocomplete queries using OpenAPI spec
JavaScript
6
star
33

demo-hnm

Jupyter Notebook
5
star
34

quantization

Rust
5
star
35

haloperidol

Antipsychotic therapy for qdrant cluster
Shell
5
star
36

mri

A simple tool to monitor process resource usage as frequent as possible
Rust
5
star
37

demo-distributed-deployment-docker

An example of setting up the distributed deployment of Qdrant with docker-compose
Shell
4
star
38

contexto

A simple script to solve contexto.me using word embeddings
JavaScript
4
star
39

page-search-js

Web interface for integrated web-site search powered by Qdrant
JavaScript
4
star
40

sparse-vectors-benchmark

This is a benchmarking tool for Qdrant's sparse vector implementation
Python
4
star
41

demo-midlibrary-explorer-nextjs

Exploration of Midjourney Library styles using Qdrant and NextJS
JavaScript
4
star
42

qdrant_python_client

Qdrant Python client, generated from OpenAPI specification (with minor fixes)
Python
3
star
43

dataset-cloud-platform-faq

HTML
3
star
44

qdrant-qa-workshop

Jupyter Notebook
3
star
45

sparse-vectors-experiments

Rust
3
star
46

qdrant-langchain-qa

HTML
2
star
47

coach

Coach running drills to train qdrant deployments
Rust
2
star
48

rust-parser

Extracts semantics from rust code
Rust
2
star
49

qdrant-stars-handbook

The primary goal of Qdrant Stars is to recognize, reward, and support our most active and helpful users making significant contributions to the vector search community. The Qdrant Stars Handbook is your go-to resource for navigating the Stars program and how to take the most advantage of it.
2
star
50

rivet-plugin-qdrant

TypeScript
2
star
51

tutorials

This repo contains tutorials, demos, and how-to guides on how to use Qdrant and adjacent technologies.
Jupyter Notebook
1
star
52

demo-qdrant-fiftyone

An example of integrating Qdrant with FiftyOne
Python
1
star
53

qdrant-genkit

Go
1
star
54

crasher

Crashing the party
Rust
1
star
55

api-reference

Repository for Qdrant's API Reference Documentation
Java
1
star