Examples of Vector Similarity Search (VSS) in Python
https://joeywhelan.blogspot.com/2022/12/redis-vector-similarity-search.html
- Provides examples of how to conduct straight vector and hybrid VSS searches.
- Python
- Download of images from Kaggle site - https://www.kaggle.com/datasets/paramaggarwal/fashion-product-images-dataset
- RediSearch 2.6/Redis JSON 2.4.
-
Clone this repo.
-
Create an images folder in the data folder and download the images from the URL above.
-
Install Python requirements (either in a virtual env or global)
pip install -r requirements.txt
- --url. Redis connection string. Default = redis://localhost:6379
- --objecttype. Redis Object Type. Default = json
- --indextype. Redis VSS Index Type. Default = flat
- --metrictype. Redis VSS Metric Type. Default = l2
python3 example.py --objecttype json --indextype hnsw --metrictype cosine
Vector Query
Query Vector Image ID:58452
ID | Score |
---|---|
58452 | 0 |
31863 | 0.12 |
46314 | 0.13 |
33909 | 0.22 |
22945 | 0.24 |
Hybrid Query
Query Vector Image ID:58452
Hybrid Query String: 2107|2656|25155|40953|34242
ID | Score |
---|---|
2656 | 0.4 |
40953 | 0.42 |
34242 | 0.49 |
25155 | 0.51 |
2107 | 0.52 |