Created
November 20, 2024 17:23
-
-
Save davidmezzetti/f0a0b92f5281924597c9d1a7bb89562e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from txtai import Embeddings | |
# In-memory data | |
data = [{"name":"John", "age": 16}, {"name":"Jon", "age": 45},{"name":"Sarah", "age": 18}] | |
# Vector embeddings index with content storage | |
embeddings = Embeddings(content=True, columns={"text": "name"}) | |
embeddings.index(data) | |
# Vector similarity | |
embeddings.search("SELECT name, age, score FROM txtai WHERE similar('jon')", 2) | |
# [{'name': 'Jon', 'age': 45, 'score': 1.0}, | |
# {'name': 'John', 'age': 16, 'score': 0.6010721921920776}] | |
# String comparison backed by SQLite | |
embeddings.search("SELECT name, age FROM txtai WHERE name like '%jon%'") | |
# [{'name': 'Jon', 'age': 45}] | |
# Vector similarity + SQL filters | |
embeddings.search("SELECT name, age, score FROM txtai WHERE similar('jon') AND score >= 0.5 AND age < 25") | |
# [{'name': 'John', 'age': 16, 'score': 0.6010721921920776}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment