π»Encoding + Inserting
Encode and inserting with VecDB
import requests
def encode_text(text, project, api_key):
return requests.post(
url="https://api-dev-aueast.relevance.ai/v1/services/encoders/textimage",
headers={"Authorization": project+ ":" + api_key},
json={
"text": text
}
).json()["vector"]import requests
def encode_image(image_url, project, api_key):
return requests.post(
url="https://api-dev-aueast.relevance.ai/v1/services/encoders/imagetext",
headers={"Authorization": project + ":" + api_key},
json={
"image": image_url
}
).json()["vector"]
# Here, we get an image url from the documents from earlier and encode them!
vector = encode_image(docs[0]['image']['coco_url'])
def encode_document(doc):
"""Encode the image urls in the documents and transforms them into vectors
"""
d['image_vector_'] = encode_image(
d['image']['coco_url'],
project=PROJECT,
api_key=API_KEY)
def chunk(docs, chunk_size=15):
"""Chunks a set of documents and inserts them!
"""
for i in range(int(len(docs) / chunk_size)):
yield docs[i:(i + 1) * chunk_size]Last updated
Was this helpful?