Skip to content

Instantly share code, notes, and snippets.

@davidmezzetti
Created January 23, 2022 12:11
Show Gist options
  • Save davidmezzetti/93d0f95c59856db18344ecf997709ee5 to your computer and use it in GitHub Desktop.
Save davidmezzetti/93d0f95c59856db18344ecf997709ee5 to your computer and use it in GitHub Desktop.
# Create an index for the list of text
embeddings.index([(uid, {"text": text, "length": len(text)}, None) for uid, text in enumerate(data)])
# Filter by score
print(embeddings.search("select text, score from txtai where similar('hiking danger') and score >= 0.15"))
# Filter by metadata field 'length'
print(embeddings.search("select text, length, score from txtai where similar('feel good story') and score >= 0.05 and length >= 40"))
# Run aggregate queries
print(embeddings.search("select count(*), min(length), max(length), sum(length) from txtai"))
print()
for x in embeddings.search("select count(*), min(length), max(length), sum(length), text, score from txtai group by text limit 10"):
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment