Vector database sharding
Multimodal search
JaguarDB quantization
JaguarDB Vector API
Best Vector databases
JaguarDB in Docker
Setup JaguarDB with tar package
Setup JaguarDB on multiple nodes
Vector index sharing
How zeromove works
Video introduction
|
|
Example: Image Search
CLIP, which stands for "Contrastive Language-Image Pretraining", is a powerful and innovative deep learning model developed by OpenAI. It is designed to bridge the gap between understanding natural language and processing visual information simultaneously. CLIP is known for its ability to understand and interpret text and images in a unified manner, making it versatile and applicable in various domains. It can answer questions about images, describe images based on textual prompts, and even generate textual descriptions for images.
The following Python example demonstrates extracting embeddings from images and searching similar images from a query image. You will need "pip install -U jaguardb-http-client" to have the jaguar http client package.
from PIL import Image from sentence_transformers import SentenceTransformer from jaguardb_http_client.JaguarHttpClient import JaguarHttpClient
url="http://192.168.8.88:8080/fwww/" jag = JaguarHttpClient(url) apikey = "demouser"
token = jag.login( apikey ) q= "create store imgvec (v vector(512, 'euclidean_fraction_float'), v:img file, cat char(16))" jag.get(q, token)
model = SentenceTransformer('clip-ViT-B-32')
images = [ Image.open('img1.jpg') ] embeddings = model.encode( images ) comma_sep_str = ",".join( [str(x) for x in embeddings[0] ]) jag.postFile(token, 'imag1.jpg', 2 ) q = "insert into imgvec values ( '" + comma_sep_str + "', 'img1.jpg', 'outdoor')" jag.post(q, token, True)
# add more images here ...
# prepare a query image images = [ Image.open('queryimg.jpg') ] embeddings = model.encode( images ) comma_sep_str = ",".join( [str(x) for x in embeddings[0] ]) qs = "select similarity(v, '" + embeddings + "','type=euclidean_fraction_float,topk=3') from imgvec" resp = jag.post(qs, token) jarr = json.loads(resp.text)
while rec in jarr: print(json.loads(rec))
The difference between image similarity search and text similarity search is that a CLIP model "clip-ViT-B-32" for images is used in computing the embeddings of image data. The size of the dimension is 512 in this context.
|