METADATA 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. Metadata-Version: 2.3
  2. Name: qdrant-client
  3. Version: 1.15.1
  4. Summary: Client library for the Qdrant vector search engine
  5. License: Apache-2.0
  6. Keywords: vector,search,neural,matching,client
  7. Author: Andrey Vasnetsov
  8. Author-email: andrey@qdrant.tech
  9. Requires-Python: >=3.9
  10. Classifier: License :: OSI Approved :: Apache Software License
  11. Classifier: Programming Language :: Python :: 3
  12. Classifier: Programming Language :: Python :: 3.9
  13. Classifier: Programming Language :: Python :: 3.10
  14. Classifier: Programming Language :: Python :: 3.11
  15. Classifier: Programming Language :: Python :: 3.12
  16. Classifier: Programming Language :: Python :: 3.13
  17. Provides-Extra: fastembed
  18. Provides-Extra: fastembed-gpu
  19. Requires-Dist: fastembed (>=0.7,<0.8) ; extra == "fastembed"
  20. Requires-Dist: fastembed-gpu (>=0.7,<0.8) ; extra == "fastembed-gpu"
  21. Requires-Dist: grpcio (>=1.41.0)
  22. Requires-Dist: httpx[http2] (>=0.20.0)
  23. Requires-Dist: numpy (>=1.21) ; python_version >= "3.10" and python_version < "3.12"
  24. Requires-Dist: numpy (>=1.21,<2.1.0) ; python_version < "3.10"
  25. Requires-Dist: numpy (>=1.26) ; python_version == "3.12"
  26. Requires-Dist: numpy (>=2.1.0) ; python_version >= "3.13"
  27. Requires-Dist: portalocker (>=2.7.0,<4.0)
  28. Requires-Dist: protobuf (>=3.20.0)
  29. Requires-Dist: pydantic (>=1.10.8,!=2.0.*,!=2.1.*,!=2.2.0)
  30. Requires-Dist: urllib3 (>=1.26.14,<3)
  31. Project-URL: Homepage, https://github.com/qdrant/qdrant-client
  32. Project-URL: Repository, https://github.com/qdrant/qdrant-client
  33. Description-Content-Type: text/markdown
  34. <p align="center">
  35. <picture>
  36. <source media="(prefers-color-scheme: dark)" srcset="https://github.com/qdrant/qdrant/raw/master/docs/logo-dark.svg">
  37. <source media="(prefers-color-scheme: light)" srcset="https://github.com/qdrant/qdrant/raw/master/docs/logo-light.svg">
  38. <img height="100" alt="Qdrant" src="https://github.com/qdrant/qdrant/raw/master/docs/logo.svg">
  39. </picture>
  40. </p>
  41. <p align="center">
  42. <b>Python Client library for the <a href="https://github.com/qdrant/qdrant">Qdrant</a> vector search engine.</b>
  43. </p>
  44. <p align=center>
  45. <a href="https://pypi.org/project/qdrant-client/"><img src="https://badge.fury.io/py/qdrant-client.svg" alt="PyPI version" height="18"></a>
  46. <a href="https://api.qdrant.tech/"><img src="https://img.shields.io/badge/Docs-OpenAPI%203.0-success" alt="OpenAPI Docs"></a>
  47. <a href="https://github.com/qdrant/qdrant-client/blob/master/LICENSE"><img src="https://img.shields.io/badge/License-Apache%202.0-success" alt="Apache 2.0 License"></a>
  48. <a href="https://qdrant.to/discord"><img src="https://img.shields.io/badge/Discord-Qdrant-5865F2.svg?logo=discord" alt="Discord"></a>
  49. <a href="https://qdrant.to/roadmap"><img src="https://img.shields.io/badge/Roadmap-2025-bc1439.svg" alt="Roadmap 2025"></a>
  50. </p>
  51. # Python Qdrant Client
  52. Client library and SDK for the [Qdrant](https://github.com/qdrant/qdrant) vector search engine.
  53. Library contains type definitions for all Qdrant API and allows to make both Sync and Async requests.
  54. Client allows calls for all [Qdrant API methods](https://api.qdrant.tech/) directly.
  55. It also provides some additional helper methods for frequently required operations, e.g. initial collection uploading.
  56. See [QuickStart](https://qdrant.tech/documentation/quick-start/#create-collection) for more details!
  57. ## Installation
  58. ```
  59. pip install qdrant-client
  60. ```
  61. ## Features
  62. - Type hints for all API methods
  63. - Local mode - use same API without running server
  64. - REST and gRPC support
  65. - Minimal dependencies
  66. - Extensive Test Coverage
  67. ## Local mode
  68. <p align="center">
  69. <!--- https://github.com/qdrant/qdrant-client/raw/master -->
  70. <img max-height="180" src="https://github.com/qdrant/qdrant-client/raw/master/docs/images/try-develop-deploy.png" alt="Qdrant">
  71. </p>
  72. Python client allows you to run same code in local mode without running Qdrant server.
  73. Simply initialize client like this:
  74. ```python
  75. from qdrant_client import QdrantClient
  76. client = QdrantClient(":memory:")
  77. # or
  78. client = QdrantClient(path="path/to/db") # Persists changes to disk
  79. ```
  80. Local mode is useful for development, prototyping and testing.
  81. - You can use it to run tests in your CI/CD pipeline.
  82. - Run it in Colab or Jupyter Notebook, no extra dependencies required. See an [example](https://colab.research.google.com/drive/1Bz8RSVHwnNDaNtDwotfPj0w7AYzsdXZ-?usp=sharing)
  83. - When you need to scale, simply switch to server mode.
  84. ## Connect to Qdrant server
  85. To connect to Qdrant server, simply specify host and port:
  86. ```python
  87. from qdrant_client import QdrantClient
  88. client = QdrantClient(host="localhost", port=6333)
  89. # or
  90. client = QdrantClient(url="http://localhost:6333")
  91. ```
  92. You can run Qdrant server locally with docker:
  93. ```bash
  94. docker run -p 6333:6333 qdrant/qdrant:latest
  95. ```
  96. See more launch options in [Qdrant repository](https://github.com/qdrant/qdrant#usage).
  97. ## Connect to Qdrant cloud
  98. You can register and use [Qdrant Cloud](https://cloud.qdrant.io/) to get a free tier account with 1GB RAM.
  99. Once you have your cluster and API key, you can connect to it like this:
  100. ```python
  101. from qdrant_client import QdrantClient
  102. qdrant_client = QdrantClient(
  103. url="https://xxxxxx-xxxxx-xxxxx-xxxx-xxxxxxxxx.us-east.aws.cloud.qdrant.io:6333",
  104. api_key="<your-api-key>",
  105. )
  106. ```
  107. ## Inference API
  108. Qdrant Client has Inference API that allows to seamlessly create embeddings and use them in Qdrant.
  109. Inference API can be used locally with FastEmbed or remotely with models available in Qdrant Cloud.
  110. ### Local Inference with FastEmbed
  111. ```
  112. pip install qdrant-client[fastembed]
  113. ```
  114. FastEmbed is a library for creating fast vector embeddings on CPU. It is based on ONNX Runtime and allows to run inference both on CPU and GPU.
  115. Qdrant Client can use FastEmbed to create embeddings and upload them to Qdrant. This allows to simplify API and make it more intuitive.
  116. ```python
  117. from qdrant_client import QdrantClient, models
  118. # running qdrant in local mode suitable for experiments
  119. client = QdrantClient(":memory:") # or QdrantClient(path="path/to/db") for local mode and persistent storage
  120. model_name = "sentence-transformers/all-MiniLM-L6-v2"
  121. payload = [
  122. {"document": "Qdrant has Langchain integrations", "source": "Langchain-docs", },
  123. {"document": "Qdrant also has Llama Index integrations", "source": "LlamaIndex-docs"},
  124. ]
  125. docs = [models.Document(text=data["document"], model=model_name) for data in payload]
  126. ids = [42, 2]
  127. client.create_collection(
  128. "demo_collection",
  129. vectors_config=models.VectorParams(
  130. size=client.get_embedding_size(model_name), distance=models.Distance.COSINE)
  131. )
  132. client.upload_collection(
  133. collection_name="demo_collection",
  134. vectors=docs,
  135. ids=ids,
  136. payload=payload,
  137. )
  138. search_result = client.query_points(
  139. collection_name="demo_collection",
  140. query=models.Document(text="This is a query document", model=model_name)
  141. ).points
  142. print(search_result)
  143. ```
  144. FastEmbed can also utilise GPU for faster embeddings. To enable GPU support, install
  145. ```bash
  146. pip install 'qdrant-client[fastembed-gpu]'
  147. ```
  148. In order to set GPU, extend documents from the previous example with `options`.
  149. ```python
  150. models.Document(text="To be computed on GPU", model=model_name, options={"cuda": True})
  151. ```
  152. > Note: `fastembed-gpu` and `fastembed` are mutually exclusive. You can only install one of them.
  153. >
  154. > If you previously installed `fastembed`, you might need to start from a fresh environment to install `fastembed-gpu`.
  155. ### Remote inference with Qdrant Cloud
  156. Qdrant Cloud provides a set of predefined models that can be used for inference without a need to install any additional libraries or host models locally. (Currently available only on paid plans.)
  157. Inference API is the same as in the local mode, but the client has to be instantiated with `cloud_inference=True`:
  158. ```python
  159. from qdrant_client import QdrantClient
  160. client = QdrantClient(
  161. url="https://xxxxxx-xxxxx-xxxxx-xxxx-xxxxxxxxx.us-east.aws.cloud.qdrant.io:6333",
  162. api_key="<your-api-key>",
  163. cloud_inference=True, # Enable remote inference
  164. )
  165. ```
  166. > Note: remote inference requires images to be provided as base64 encoded strings or urls
  167. ## Examples
  168. Create a new collection
  169. ```python
  170. from qdrant_client.models import Distance, VectorParams
  171. client.create_collection(
  172. collection_name="my_collection",
  173. vectors_config=VectorParams(size=100, distance=Distance.COSINE),
  174. )
  175. ```
  176. Insert vectors into a collection
  177. ```python
  178. import numpy as np
  179. from qdrant_client.models import PointStruct
  180. vectors = np.random.rand(100, 100)
  181. # NOTE: consider splitting the data into chunks to avoid hitting the server's payload size limit
  182. # or use `upload_collection` or `upload_points` methods which handle this for you
  183. # WARNING: uploading points one-by-one is not recommended due to requests overhead
  184. client.upsert(
  185. collection_name="my_collection",
  186. points=[
  187. PointStruct(
  188. id=idx,
  189. vector=vector.tolist(),
  190. payload={"color": "red", "rand_number": idx % 10}
  191. )
  192. for idx, vector in enumerate(vectors)
  193. ]
  194. )
  195. ```
  196. Search for similar vectors
  197. ```python
  198. query_vector = np.random.rand(100)
  199. hits = client.query_points(
  200. collection_name="my_collection",
  201. query=query_vector,
  202. limit=5 # Return 5 closest points
  203. )
  204. ```
  205. Search for similar vectors with filtering condition
  206. ```python
  207. from qdrant_client.models import Filter, FieldCondition, Range
  208. hits = client.query_points(
  209. collection_name="my_collection",
  210. query=query_vector,
  211. query_filter=Filter(
  212. must=[ # These conditions are required for search results
  213. FieldCondition(
  214. key='rand_number', # Condition based on values of `rand_number` field.
  215. range=Range(
  216. gte=3 # Select only those results where `rand_number` >= 3
  217. )
  218. )
  219. ]
  220. ),
  221. limit=5 # Return 5 closest points
  222. )
  223. ```
  224. See more examples in our [Documentation](https://qdrant.tech/documentation/)!
  225. ### gRPC
  226. To enable (typically, much faster) collection uploading with gRPC, use the following initialization:
  227. ```python
  228. from qdrant_client import QdrantClient
  229. client = QdrantClient(host="localhost", grpc_port=6334, prefer_grpc=True)
  230. ```
  231. ## Async client
  232. Starting from version 1.6.1, all python client methods are available in async version.
  233. To use it, just import `AsyncQdrantClient` instead of `QdrantClient`:
  234. ```python
  235. import asyncio
  236. import numpy as np
  237. from qdrant_client import AsyncQdrantClient, models
  238. async def main():
  239. # Your async code using QdrantClient might be put here
  240. client = AsyncQdrantClient(url="http://localhost:6333")
  241. await client.create_collection(
  242. collection_name="my_collection",
  243. vectors_config=models.VectorParams(size=10, distance=models.Distance.COSINE),
  244. )
  245. await client.upsert(
  246. collection_name="my_collection",
  247. points=[
  248. models.PointStruct(
  249. id=i,
  250. vector=np.random.rand(10).tolist(),
  251. )
  252. for i in range(100)
  253. ],
  254. )
  255. res = await client.query_points(
  256. collection_name="my_collection",
  257. query=np.random.rand(10).tolist(), # type: ignore
  258. limit=10,
  259. )
  260. print(res)
  261. asyncio.run(main())
  262. ```
  263. Both, gRPC and REST API are supported in async mode.
  264. More examples can be found [here](./tests/test_async_qdrant_client.py).
  265. ### Development
  266. This project uses git hooks to run code formatters.
  267. Set up hooks with `pre-commit install` before making contributions.