Skip to content

Instantly share code, notes, and snippets.

@kacperlukawski
Last active December 11, 2023 04:32
Show Gist options
  • Save kacperlukawski/2d3a3225f15a4cc5772cd1c81866340d to your computer and use it in GitHub Desktop.
Save kacperlukawski/2d3a3225f15a4cc5772cd1c81866340d to your computer and use it in GitHub Desktop.
Qdrant tips&tricks
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "80d07e96",
"metadata": {
"ExecuteTime": {
"end_time": "2023-03-13T11:37:33.419874Z",
"start_time": "2023-03-13T11:37:33.257995Z"
}
},
"outputs": [],
"source": [
"import config\n",
"import func\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3aab3275",
"metadata": {
"ExecuteTime": {
"end_time": "2023-03-13T11:37:37.227738Z",
"start_time": "2023-03-13T11:37:37.218943Z"
}
},
"outputs": [],
"source": [
"from tqdm import tqdm\n",
"from qdrant_client import QdrantClient\n",
"from qdrant_client.http import models as rest"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "9bc3516e",
"metadata": {
"ExecuteTime": {
"end_time": "2023-03-13T11:37:42.230171Z",
"start_time": "2023-03-13T11:37:42.127463Z"
}
},
"outputs": [],
"source": [
"client = QdrantClient(\n",
" url=\"http://localhost\",\n",
" prefer_grpc=True,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "96250102",
"metadata": {},
"source": [
"# Scroll"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "4d888573",
"metadata": {
"ExecuteTime": {
"end_time": "2023-03-13T11:39:11.976503Z",
"start_time": "2023-03-13T11:39:11.961281Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"([Record(id='0000714b-e6e9-496c-a9df-c9c2d9a76385', payload={'prod_name': 'Topi Dress', 'perceived_colour_value_name': 'Dark', 'section_no': 53, 'graphical_appearance_no': 1010002, 'index_group_name': 'Divided', 'index_name': 'Divided', 'perceived_colour_master_name': 'Black', 'garment_group_name': 'Dresses Ladies', 'department_no': 1344, 'department_name': 'Dresses', 'product_type_name': 'Dress', 'perceived_colour_value_id': 4, 'garment_group_no': 1013, 'product_group_name': 'Garment Full body', 'section_name': 'Divided Collection', 'perceived_colour_master_id': 5, 'colour_group_code': 9, 'product_type_no': 265, 'index_group_no': 2, 'index_code': 'D', 'detail_desc': 'Short, fitted dress in sturdy jersey with a round neckline and short sleeves.', 'graphical_appearance_name': 'Application/3D', 'product_code': 862693, 'colour_group_name': 'Black'}, vector=None),\n",
" Record(id='0002ab46-a7ef-4122-aecc-d170335740c8', payload={'prod_name': '1 - PACK', 'section_no': 6, 'perceived_colour_value_name': 'Bright', 'graphical_appearance_no': 1010016, 'index_group_name': 'Ladieswear', 'index_name': 'Ladieswear', 'perceived_colour_master_name': 'Red', 'garment_group_name': 'Jersey Fancy', 'department_no': 1660, 'section_name': 'Womens Casual', 'product_type_name': 'T-shirt', 'perceived_colour_value_id': 5, 'garment_group_no': 1005, 'department_name': 'Jersey', 'product_group_name': 'Garment Upper body', 'index_group_no': 1, 'colour_group_code': 42, 'product_type_no': 255, 'perceived_colour_master_id': 18, 'index_code': 'A', 'detail_desc': 'Fitted T-shirt in soft organic cotton jersey.', 'product_code': 573284, 'graphical_appearance_name': 'Solid', 'colour_group_name': 'Red'}, vector=None),\n",
" Record(id='0002d7bf-e157-4eca-aba7-5687bd3013fc', payload={'prod_name': 'Flirty Romi waterbottle', 'section_no': 66, 'perceived_colour_value_name': 'Dusty Light', 'graphical_appearance_no': 1010001, 'index_group_name': 'Ladieswear', 'index_name': 'Ladies Accessories', 'perceived_colour_master_name': 'Pink', 'perceived_colour_value_id': 1, 'department_no': 3419, 'section_name': 'Womens Small accessories', 'product_type_name': 'Other accessories', 'garment_group_name': 'Accessories', 'garment_group_no': 1019, 'product_group_name': 'Accessories', 'department_name': 'Other items', 'perceived_colour_master_id': 4, 'colour_group_code': 51, 'product_type_no': 78, 'index_group_no': 1, 'index_code': 'C', 'detail_desc': 'Plastic water bottle with a screw top and practical wrist strap that also holds the top in place. Capacity 550 ml.', 'product_code': 344956, 'graphical_appearance_name': 'All over pattern', 'colour_group_name': 'Light Pink'}, vector=None)],\n",
" '00033c89-0180-4dfc-be41-f1271baa564d')"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"client.scroll(\n",
" collection_name=config.COLLECTION_NAME,\n",
" limit=3,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "c5871660",
"metadata": {},
"source": [
"# Recommendations"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "e7133383",
"metadata": {
"ExecuteTime": {
"end_time": "2023-03-13T11:42:04.816345Z",
"start_time": "2023-03-13T11:42:04.742284Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"[ScoredPoint(id='69ebcd42-b478-42b2-b795-a4b0979b6b76', version=27, score=0.8442549705505371, payload={'prod_name': 'Brit Baby Tee', 'section_no': 51, 'perceived_colour_value_name': 'Dark', 'graphical_appearance_no': 1010016, 'index_group_name': 'Divided', 'index_name': 'Divided', 'perceived_colour_master_name': 'Black', 'garment_group_name': 'Jersey Basic', 'department_no': 1643, 'department_name': 'Basic 1', 'product_type_name': 'T-shirt', 'perceived_colour_value_id': 4, 'garment_group_no': 1002, 'product_group_name': 'Garment Upper body', 'section_name': 'Divided Basics', 'perceived_colour_master_id': 5, 'colour_group_code': 9, 'product_type_no': 255, 'index_group_no': 2, 'index_code': 'D', 'detail_desc': 'Short, fitted top in ribbed cotton jersey with short sleeves.', 'graphical_appearance_name': 'Solid', 'product_code': 624486, 'colour_group_name': 'Black'}, vector=None),\n",
" ScoredPoint(id='4345b525-4bec-486a-802b-332e1b8ed8a1', version=41, score=0.8381525278091431, payload={'prod_name': 'Nancy t-shirt', 'section_no': 16, 'perceived_colour_value_name': 'Dark', 'graphical_appearance_no': 1010016, 'index_group_name': 'Ladieswear', 'index_name': 'Ladieswear', 'perceived_colour_master_name': 'Black', 'perceived_colour_value_id': 4, 'department_no': 1676, 'section_name': 'Womens Everyday Basics', 'product_type_name': 'T-shirt', 'department_name': 'Jersey Basic', 'product_group_name': 'Garment Upper body', 'garment_group_no': 1002, 'garment_group_name': 'Jersey Basic', 'index_group_no': 1, 'colour_group_code': 9, 'product_type_no': 255, 'perceived_colour_master_id': 5, 'index_code': 'A', 'detail_desc': 'V-neck T-shirt in soft, organic cotton jersey.', 'product_code': 880001, 'graphical_appearance_name': 'Solid', 'colour_group_name': 'Black'}, vector=None),\n",
" ScoredPoint(id='2c028563-573c-4453-adcd-13f7f2974616', version=8, score=0.8370258808135986, payload={'prod_name': 'RONNY R-NECK', 'perceived_colour_value_name': 'Dark', 'section_no': 26, 'graphical_appearance_no': 1010016, 'index_group_name': 'Menswear', 'index_name': 'Menswear', 'perceived_colour_master_name': 'Green', 'perceived_colour_value_id': 4, 'department_no': 5832, 'department_name': 'Light Basic Jersey', 'product_type_name': 'T-shirt', 'garment_group_name': 'Jersey Basic', 'product_group_name': 'Garment Upper body', 'garment_group_no': 1002, 'section_name': 'Men Underwear', 'index_group_no': 3, 'colour_group_code': 93, 'product_type_no': 255, 'perceived_colour_master_id': 19, 'index_code': 'F', 'detail_desc': 'Round-necked T-shirt in soft cotton jersey.', 'graphical_appearance_name': 'Solid', 'product_code': 685816, 'colour_group_name': 'Dark Green'}, vector=None)]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"client.recommend(\n",
" collection_name=config.COLLECTION_NAME,\n",
" positive=[\"0000714b-e6e9-496c-a9df-c9c2d9a76385\"],\n",
" negative=[\"0002d7bf-e157-4eca-aba7-5687bd3013fc\"],\n",
" limit=3,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "7690837f",
"metadata": {
"ExecuteTime": {
"end_time": "2023-03-13T11:42:27.712831Z",
"start_time": "2023-03-13T11:42:27.704975Z"
}
},
"source": [
"# Batch methods"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "ed49c747",
"metadata": {
"ExecuteTime": {
"end_time": "2023-03-13T11:47:49.856877Z",
"start_time": "2023-03-13T11:47:49.830146Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"[[ScoredPoint(id='ca4bd6f8-5697-4cd6-ac8b-2f0923ac14e0', version=0, score=0.2867836654186249, payload={'prod_name': 'Dolores', 'section_no': 11, 'perceived_colour_value_name': 'Dusty Light', 'graphical_appearance_no': 1010017, 'index_group_name': 'Ladieswear', 'index_name': 'Ladieswear', 'perceived_colour_master_name': 'White', 'garment_group_name': 'Knitwear', 'department_no': 1616, 'section_name': 'Womens Tailoring', 'product_type_name': 'Sweater', 'department_name': 'Knitwear', 'garment_group_no': 1003, 'perceived_colour_value_id': 1, 'product_group_name': 'Garment Upper body', 'index_group_no': 1, 'colour_group_code': 11, 'product_type_no': 252, 'perceived_colour_master_id': 9, 'index_code': 'A', 'detail_desc': 'Jumper in a soft, fine-knit viscose blend with a round neckline, buttons on the shoulders and ribbing around the neckline, cuffs and hem.', 'product_code': 719589, 'graphical_appearance_name': 'Stripe', 'colour_group_name': 'Off White'}, vector=None)],\n",
" [ScoredPoint(id='ca4bd6f8-5697-4cd6-ac8b-2f0923ac14e0', version=0, score=0.29146379232406616, payload={}, vector=None),\n",
" ScoredPoint(id='2a29c3b7-2c18-4fb6-82b5-1d9cf5d34d1d', version=2, score=0.28514474630355835, payload={}, vector=None)]]"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"client.search_batch(\n",
" collection_name=config.COLLECTION_NAME,\n",
" requests=[\n",
" rest.SearchRequest(\n",
" vector=np.random.random(2048).tolist(),\n",
" with_payload=True,\n",
" limit=1,\n",
" ),\n",
" rest.SearchRequest(\n",
" vector=np.random.random(2048).tolist(),\n",
" with_payload=False,\n",
" limit=2,\n",
" ),\n",
" ]\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6c86ce0a",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment