mirror of
https://github.com/asg017/sqlite-vec.git
synced 2026-04-26 01:06:27 +02:00
fmt
This commit is contained in:
parent
b923c596df
commit
2fdd760dd1
2 changed files with 91 additions and 53 deletions
|
|
@ -613,7 +613,8 @@ static int fvec_from_value(sqlite3_value *value, f32 **vector,
|
||||||
}
|
}
|
||||||
|
|
||||||
*pzErr = sqlite3_mprintf(
|
*pzErr = sqlite3_mprintf(
|
||||||
"Input must have type BLOB (compact format) or TEXT (JSON), found %s", type_name(value_type));
|
"Input must have type BLOB (compact format) or TEXT (JSON), found %s",
|
||||||
|
type_name(value_type));
|
||||||
return SQLITE_ERROR;
|
return SQLITE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -799,7 +800,6 @@ int vector_from_value(sqlite3_value *value, void **vector, size_t *dimensions,
|
||||||
return SQLITE_ERROR;
|
return SQLITE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int ensure_vector_match(sqlite3_value *aValue, sqlite3_value *bValue, void **a,
|
int ensure_vector_match(sqlite3_value *aValue, sqlite3_value *bValue, void **a,
|
||||||
void **b, enum VectorElementType *element_type,
|
void **b, enum VectorElementType *element_type,
|
||||||
size_t *dimensions, vector_cleanup *outACleanup,
|
size_t *dimensions, vector_cleanup *outACleanup,
|
||||||
|
|
|
||||||
|
|
@ -998,7 +998,7 @@ def test_vec0_updates():
|
||||||
{
|
{
|
||||||
"x": "[.1, .1, .1, .1, -.1, -.1, -.1, -.1]",
|
"x": "[.1, .1, .1, .1, -.1, -.1, -.1, -.1]",
|
||||||
"y": "[-.2, .2, .2, .2, .2, .2, -.2, .2]",
|
"y": "[-.2, .2, .2, .2, .2, .2, -.2, .2]",
|
||||||
"z": "[.3, .3, .3, .3, .3, .3, .3, .3]"
|
"z": "[.3, .3, .3, .3, .3, .3, .3, .3]",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert execute_all(db, "select * from t3") == [
|
assert execute_all(db, "select * from t3") == [
|
||||||
|
|
@ -1017,12 +1017,23 @@ def test_vec0_updates():
|
||||||
{
|
{
|
||||||
"rowid": 3,
|
"rowid": 3,
|
||||||
"aaa": _f32([0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]),
|
"aaa": _f32([0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]),
|
||||||
"bbb": _int8([37, 37, 37, 37, 37, 37, 37, 37, ]),
|
"bbb": _int8(
|
||||||
|
[
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
]
|
||||||
|
),
|
||||||
"ccc": bitmap("11111111"),
|
"ccc": bitmap("11111111"),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
db.execute("UPDATE t3 SET aaa = ? WHERE rowid = 1", ['[.9,.9,.9,.9,.9,.9,.9,.9]'])
|
db.execute("UPDATE t3 SET aaa = ? WHERE rowid = 1", ["[.9,.9,.9,.9,.9,.9,.9,.9]"])
|
||||||
assert execute_all(db, "select * from t3") == [
|
assert execute_all(db, "select * from t3") == [
|
||||||
{
|
{
|
||||||
"rowid": 1,
|
"rowid": 1,
|
||||||
|
|
@ -1039,39 +1050,64 @@ def test_vec0_updates():
|
||||||
{
|
{
|
||||||
"rowid": 3,
|
"rowid": 3,
|
||||||
"aaa": _f32([0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]),
|
"aaa": _f32([0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]),
|
||||||
"bbb": _int8([37, 37, 37, 37, 37, 37, 37, 37, ]),
|
"bbb": _int8(
|
||||||
|
[
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
]
|
||||||
|
),
|
||||||
"ccc": bitmap("11111111"),
|
"ccc": bitmap("11111111"),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
# EVIDENCE-OF: V15203_32042 vec0 UPDATE validates vector
|
# EVIDENCE-OF: V15203_32042 vec0 UPDATE validates vector
|
||||||
with _raises('Updated vector for the "aaa" column is invalid: invalid float32 vector BLOB length. Must be divisible by 4, found 1'):
|
with _raises(
|
||||||
|
'Updated vector for the "aaa" column is invalid: invalid float32 vector BLOB length. Must be divisible by 4, found 1'
|
||||||
|
):
|
||||||
db.execute("UPDATE t3 SET aaa = X'AB' WHERE rowid = 1")
|
db.execute("UPDATE t3 SET aaa = X'AB' WHERE rowid = 1")
|
||||||
|
|
||||||
# EVIDENCE-OF: V25739_09810 vec0 UPDATE validates dimension length
|
# EVIDENCE-OF: V25739_09810 vec0 UPDATE validates dimension length
|
||||||
with _raises('Dimension mismatch for new updated vector for the "aaa" column. Expected 8 dimensions but received 1.'):
|
with _raises(
|
||||||
|
'Dimension mismatch for new updated vector for the "aaa" column. Expected 8 dimensions but received 1.'
|
||||||
|
):
|
||||||
db.execute("UPDATE t3 SET aaa = vec_bit(X'AABBCCDD') WHERE rowid = 1")
|
db.execute("UPDATE t3 SET aaa = vec_bit(X'AABBCCDD') WHERE rowid = 1")
|
||||||
|
|
||||||
# EVIDENCE-OF: V03643_20481 vec0 UPDATE validates vector column type
|
# EVIDENCE-OF: V03643_20481 vec0 UPDATE validates vector column type
|
||||||
with _raises('Updated vector for the "bbb" column is expected to be of type int8, but a float32 vector was provided.'):
|
with _raises(
|
||||||
|
'Updated vector for the "bbb" column is expected to be of type int8, but a float32 vector was provided.'
|
||||||
|
):
|
||||||
db.execute("UPDATE t3 SET bbb = X'ABABABAB' WHERE rowid = 1")
|
db.execute("UPDATE t3 SET bbb = X'ABABABAB' WHERE rowid = 1")
|
||||||
|
|
||||||
db.execute("CREATE VIRTUAL TABLE t2 USING vec0(a float[2], b float[2])")
|
db.execute("CREATE VIRTUAL TABLE t2 USING vec0(a float[2], b float[2])")
|
||||||
db.execute("INSERT INTO t2(rowid, a, b) VALUES (1, '[.1, .1]', '[.2, .2]')")
|
db.execute("INSERT INTO t2(rowid, a, b) VALUES (1, '[.1, .1]', '[.2, .2]')")
|
||||||
assert execute_all(db, "select * from t2") == [{
|
assert execute_all(db, "select * from t2") == [
|
||||||
'rowid': 1,
|
{
|
||||||
'a': _f32([.1, .1]),
|
"rowid": 1,
|
||||||
'b': _f32([.2, .2]),
|
"a": _f32([0.1, 0.1]),
|
||||||
}]
|
"b": _f32([0.2, 0.2]),
|
||||||
|
}
|
||||||
|
]
|
||||||
# sanity check: the 1st column UPDATE "works", but since the 2nd one fails,
|
# sanity check: the 1st column UPDATE "works", but since the 2nd one fails,
|
||||||
# then aaa should remain unchanged.
|
# then aaa should remain unchanged.
|
||||||
with _raises('Dimension mismatch for new updated vector for the "b" column. Expected 2 dimensions but received 3.'):
|
with _raises(
|
||||||
db.execute("UPDATE t2 SET a = '[.11, .11]', b = '[.22, .22, .22]' WHERE rowid = 1")
|
'Dimension mismatch for new updated vector for the "b" column. Expected 2 dimensions but received 3.'
|
||||||
assert execute_all(db, "select * from t2") == [{
|
):
|
||||||
'rowid': 1,
|
db.execute(
|
||||||
'a': _f32([.1, .1]),
|
"UPDATE t2 SET a = '[.11, .11]', b = '[.22, .22, .22]' WHERE rowid = 1"
|
||||||
'b': _f32([.2, .2]),
|
)
|
||||||
}]
|
assert execute_all(db, "select * from t2") == [
|
||||||
|
{
|
||||||
|
"rowid": 1,
|
||||||
|
"a": _f32([0.1, 0.1]),
|
||||||
|
"b": _f32([0.2, 0.2]),
|
||||||
|
}
|
||||||
|
]
|
||||||
# TODO: set UPDATEs on int8/bit columns
|
# TODO: set UPDATEs on int8/bit columns
|
||||||
|
|
||||||
# db.execute("UPDATE t3 SET ccc = vec_bit(?) WHERE rowid = 3", [bitmap('01010101')])
|
# db.execute("UPDATE t3 SET ccc = vec_bit(?) WHERE rowid = 3", [bitmap('01010101')])
|
||||||
|
|
@ -1108,7 +1144,8 @@ def test_vec0_text_pk():
|
||||||
);
|
);
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
db.executemany("INSERT INTO t VALUES (:t_id, :aaa, :bbb)",
|
db.executemany(
|
||||||
|
"INSERT INTO t VALUES (:t_id, :aaa, :bbb)",
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"t_id": "t_1",
|
"t_id": "t_1",
|
||||||
|
|
@ -1129,6 +1166,7 @@ def test_vec0_text_pk():
|
||||||
)
|
)
|
||||||
assert execute_all(db, "select * from t") == []
|
assert execute_all(db, "select * from t") == []
|
||||||
|
|
||||||
|
|
||||||
def authorizer_deny_on(operation, x1, x2=None):
|
def authorizer_deny_on(operation, x1, x2=None):
|
||||||
def _auth(op, p1, p2, p3, p4):
|
def _auth(op, p1, p2, p3, p4):
|
||||||
if op == operation and p1 == x1 and p2 == x2:
|
if op == operation and p1 == x1 and p2 == x2:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue