timescale / python-vector

https://timescale.github.io/python-vector/
Apache License 2.0
20 stars 1 forks source link

Adds support for metadata values of type array #18

Closed jgpruitt closed 5 months ago

jgpruitt commented 7 months ago

Metadata values containing jsonb arrays are now supported. Predicates can take a list as a value. A comparison operator of "@>" now tests for array containment. This is an indexed operation.

await vec.upsert([
    (uuid.uuid4(), '''{"key0": [1,2,3,4]}''', "the brown fox", [1.0, 1.8]),
    (uuid.uuid4(), '''{"key0": [5,6,7], "key3": 3}''', "the brown fox", [1.0, 1.8]),
])
rec = await vec.search([1.0, 2.0], limit=4, predicates=Predicates("key0", "@>", [1, 2]))
assert len(rec) == 1
rec = await vec.search([1.0, 2.0], limit=4, predicates=Predicates("key0", "@>", [3, 7]))
assert len(rec) == 0
rec = await vec.search([1.0, 2.0], limit=4, predicates=Predicates("key0", "@>", [9]))
assert len(rec) == 0
rec = await vec.search([1.0, 2.0], limit=4, predicates=Predicates("key0", "@>", [4]))
assert len(rec) == 1

rec = await vec.search([1.0, 2.0], limit=4, predicates=Predicates("key0", "@>", [6,7]) and Predicates("key3","==", 3))
assert len(rec) == 1
rec = await vec.search([1.0, 2.0], limit=4, predicates=Predicates("key0", "@>", [6,7]) and Predicates("key3","==", 6))
assert len(rec) == 0