Skip to content

Commit

Permalink
test-metadata.py
Browse files Browse the repository at this point in the history
  • Loading branch information
asg017 committed Nov 14, 2024
1 parent 9cba8ff commit 3e6759c
Show file tree
Hide file tree
Showing 5 changed files with 480 additions and 5 deletions.
11 changes: 11 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,14 @@ The fourth character of the block is a `_` filler.
`argv[i]` is the value of the rowid or id to match against for the point query.

The remaining 3 characters of the block are `_` fillers.

#### `VEC0_IDXSTR_KIND_METADATA_CONSTRAINT` (`'&'`)

`argv[i]` is the value of the `WHERE` constraint for a metdata column in a KNN query.

The second character of the block denotes which metadata column the constraint belongs to, using `A` to denote the first metadata column column, `B` for the second, etc. It is encoded with `'A' + metadata_idx` and can be decoded with `c - 'A'`.

The third character of the block is the constraint operator. It will be one of `enum vec0_metadata_operator`, as only a subset of operators are supported on metadata column KNN filters.

The foruth character of the block is a `_` filler.

7 changes: 4 additions & 3 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- DELETE and UPDATE support
- large strings
- date/datetime
- `v in (...)` handling
- remaining TODO items
- dictionary encoding?
- later
- `v in (...)` handling
- remaining TODO items
- dictionary encoding?
24 changes: 22 additions & 2 deletions sqlite-vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -4074,7 +4074,12 @@ int vec0_result_metadata_value_for_rowid(vec0_vtab *p, i64 rowid, int metadata_i
break;
}
case VEC0_METADATA_COLUMN_KIND_INT64: {
// TODO handle int64 values
i64 value;
rc = sqlite3_blob_read(blobValue, &value, sizeof(value), chunk_offset * sizeof(i64));
if(rc != SQLITE_OK) {
goto done;
}
sqlite3_result_int64(context, value);
break;
}
case VEC0_METADATA_COLUMN_KIND_FLOAT: {
Expand All @@ -4087,7 +4092,13 @@ int vec0_result_metadata_value_for_rowid(vec0_vtab *p, i64 rowid, int metadata_i
break;
}
case VEC0_METADATA_COLUMN_KIND_DOUBLE: {
// TODO handle double values
double value;
rc = sqlite3_blob_read(blobValue, &value, sizeof(value), chunk_offset * sizeof(double));
if(rc != SQLITE_OK) {
goto done;
}
sqlite3_result_double(context, value);
break;
break;
}
case VEC0_METADATA_COLUMN_KIND_TEXT: {
Expand Down Expand Up @@ -5483,6 +5494,15 @@ static int vec0BestIndex(sqlite3_vtab *pVTab, sqlite3_index_info *pIdxInfo) {
value = VEC0_METADATA_OPERATOR_NE;
break;
}
default: {
// IMP: V16511_00582
rc = SQLITE_ERROR;
vtab_set_error(pVTab,
"An illegal WHERE constraint was provided on a vec0 metadata column in a KNN query. "
"Only one of EQUALS, GREATER_THAN, LESS_THAN_OR_EQUAL, LESS_THAN, GREATER_THAN_OR_EQUAL, NOT_EQUALS is allowed."
);
goto done;
}
}

if(value) {
Expand Down
Loading

0 comments on commit 3e6759c

Please sign in to comment.