Skip to content

Instantly share code, notes, and snippets.

@davidmezzetti
Created January 23, 2022 12:16
Show Gist options
  • Save davidmezzetti/e7d8621c4cd6f08a1b7f94f13c9e5990 to your computer and use it in GitHub Desktop.
Save davidmezzetti/e7d8621c4cd6f08a1b7f94f13c9e5990 to your computer and use it in GitHub Desktop.
import urllib
from IPython.display import Image
# Get an image
request = urllib.request.urlopen("https://raw.githubusercontent.com/neuml/txtai/master/demo.gif")
# Upsert new record having both text and an object
embeddings.upsert([("txtai", {"text": "txtai executes machine-learning workflows to transform data and build AI-powered semantic search applications.", "object": request.read()}, None)])
# Query txtai for the most similar result to "machine learning" and get associated object
result = embeddings.search("select object from txtai where similar('machine learning') limit 1")[0]["object"]
# Display image
Image(result.getvalue(), width=600)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment