* Add TS examples for Documentation/Concepts * Minor FAQ improvements: spelling & formatting (#318) * Minor spelling and formatting improvements in FAQ * Add unused RAM is wasted RAM quote, improve memory text * Add TypeScript version of Quickstart (#378) * Minor FAQ improvements: spelling & formatting (#318) * Minor spelling and formatting improvements in FAQ * Add unused RAM is wasted RAM quote, improve memory text * Add TS version of quickstart --------- Co-authored-by: Tim Visée <tim@visee.me> * Add TS examples to Documentation / Guides * Fix terminology * Add TS examples to Documentation / Cloud * Add TS version of bulk upload tutorial * Format tutorials with black * Move author data to [params.author] (#385) * Add TS examples for Documentation/Concepts * Add TypeScript version of Quickstart (#378) * Minor FAQ improvements: spelling & formatting (#318) * Minor spelling and formatting improvements in FAQ * Add unused RAM is wasted RAM quote, improve memory text * Add TS version of quickstart --------- Co-authored-by: Tim Visée <tim@visee.me> * Add TS examples to Documentation / Guides * Fix terminology * Add TS examples to Documentation / Cloud * Add TS version of bulk upload tutorial * Format tutorials with black --------- Co-authored-by: Tim Visée <tim@visee.me>
6.7 KiB
title, weight, aliases
| title | weight | aliases | |
|---|---|---|---|
| Quickstart | 11 |
|
Quickstart
In this short example, you will use the Python Client to create a Collection, load data into it and run a basic search query.
Download and run
First, download the latest Qdrant image from Dockerhub:
docker pull qdrant/qdrant
Then, run the service:
docker run -p 6333:6333 \
-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:
- API: localhost:6333
- Web UI: localhost:6333/dashboard
Initialize the client
from qdrant_client import QdrantClient
client = QdrantClient("localhost", port=6333)
import { QdrantClient } from "@qdrant/js-client-rest";
const client = new QdrantClient({ host: "localhost", port: 6333 });
Create a 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),
)
await client.createCollection("test_collection", {
vectors: { size: 4, distance: "Dot" },
});
Add vectors
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)
const operationInfo = await client.upsert("test_collection", {
wait: true,
points: [
{ id: 1, vector: [0.05, 0.61, 0.76, 0.74], payload: { city: "Berlin" } },
{ id: 2, vector: [0.19, 0.81, 0.75, 0.11], payload: { city: "London" } },
{ id: 3, vector: [0.36, 0.55, 0.47, 0.94], payload: { city: "Moscow" } },
{ id: 4, vector: [0.18, 0.01, 0.85, 0.80], payload: { city: "New York" } },
{ id: 5, vector: [0.24, 0.18, 0.22, 0.44], payload: { city: "Beijing" } },
{ id: 6, vector: [0.35, 0.08, 0.11, 0.44], payload: { city: "Mumbai" } },
],
});
console.debug(operationInfo);
Response:
operation_id=0 status=<UpdateStatus.COMPLETED: 'completed'>
{ operation_id: 0, status: 'completed' }
Run a 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)
let searchResult = await client.search("test_collection", {
vector: [0.2, 0.1, 0.9, 0.7],
limit: 3,
});
console.debug(searchResult);
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)
[
{
id: 4,
version: 0,
score: 1.362,
payload: { city: "New York" },
vector: null,
},
{
id: 1,
version: 0,
score: 1.273,
payload: { city: "Berlin" },
vector: null,
},
{
id: 3,
version: 0,
score: 1.208,
payload: { city: "Moscow" },
vector: null,
},
];
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.
Add a 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"))]
),
limit=3,
)
print(search_result)
searchResult = await client.search("test_collection", {
vector: [0.2, 0.1, 0.9, 0.7],
filter: {
must: [{ key: "city", match: { value: "London" } }],
},
limit: 3,
});
console.debug(searchResult);
Response:
ScoredPoint(id=2, version=0, score=0.871, payload={"city": "London"}, vector=None)
[
{
id: 2,
version: 0,
score: 0.871,
payload: { city: "London" },
vector: null,
},
];
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.
Next steps
Now you know how Qdrant works. Getting started with Qdrant Cloud is just as easy. Create an account and use our SaaS completely free. We will take care of infrastructure maintenance and software updates.
To move onto some more complex examples of vector search, read our Tutorials and create your own app with the help of our Examples.
Note: There is another way of running Qdrant locally. If you are a Python developer, we recommend that you try Local Mode in Qdrant Client, as it only takes a few moments to get setup.