Skip to content

Instantly share code, notes, and snippets.

@davidmezzetti
Last active August 18, 2021 14:29
Show Gist options
  • Save davidmezzetti/2c8fd02a58d2c844d3ef427bde26e588 to your computer and use it in GitHub Desktop.
Save davidmezzetti/2c8fd02a58d2c844d3ef427bde26e588 to your computer and use it in GitHub Desktop.
# Create an index for the list of text
embeddings.index([(uid, text, None) for uid, text in enumerate(data)])
print("%-20s %s" % ("Query", "Best Match"))
print("-" * 50)
# Run an embeddings search for each query
for query in ("feel good story", "climate change", "public health story", "war", "wildlife",
"asia", "lucky", "dishonest junk"):
# Extract uid of first result
# search result format: (uid, score)
uid = embeddings.search(query, 1)[0][0]
# Print text
print("%-20s %s" % (query, data[uid]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment