mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
* vector: derive the indexed metadata key columns An indexed metadata key is a hidden `_mk_<n>` column of List<Utf8>: the strings an S3 `$eq` on a string matches, that is the value when it is a string or the string elements of an array, and nothing for any other type or a missing key. The field metadata names the key and its state (`building` or `ready`). The module derives the column from metadata given as JSON (the write path) or as stored (jsonb or JSON text, for a backfill), and reads the indexed keys from a schema. It lives in the worker crate so the engine and the worker share it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * vector: fill the indexed metadata key columns on PutVectors PutVectors builds its batch against the table's current schema. Once a table has indexed metadata key columns, the three-column batch no longer matches that schema and the write fails. Fill each `_mk_*` column the schema has from the row's metadata, whatever the key's state; a column the engine does not know still fails the request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * vector: answer string $eq and $in on a ready indexed key from its column The gateway renders a string `$eq` or `$in` on a key as an OR of `json_extract(metadata, P) = '"v"'` (or IN) and `json_array_contains(metadata, P, '"v"')` over the same values. On the parsed filter, a top-level conjunct of that shape on a key whose column is `ready` becomes `array_has` / `array_has_any` on the column, which its LABEL_LIST index answers. The two halves must name the same key and the same strings, the scalar half in the text json_extract returns for them; anything else, including `$ne`, `$nin`, `$exists`, numbers and booleans, stays on the JSON path, and the other conjuncts still apply. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * vector: score few indexed matches exactly, per scope With a ready indexed key in the filter, `ann` first counts the rows of its scope that the key's conjuncts match, through the scalar index. When they are at most the limit it scores them exactly over that scope, the way the short-result fallback does; above it, the vector index searches with the indexed prefilter, and the fallback still applies. The scope is the one `exact_in_scope` scores, so per-scope exact answers merge into the global exact top-k. The limit is `Query::exact_match_limit` (None takes 256; 0 never counts), set by the engine's --exact-match-limit (WEED_VECTOR_EXACT_MATCH_LIMIT). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * vector: count filtered queries by metadata key For each index, the engine counts its QueryVectors calls by the metadata keys of the parsed filter, with their total latency and the operand types each key was compared with, over the last hour in 5-minute buckets. At most 512 indexes and 32 keys per index are kept (an idle key makes room; otherwise the index is marked truncated), and the stats are not exported as metrics labels. The new FilterStats RPC returns an index's stats; the gateway's discovery client forwards it like the other calls. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * vector: report the metadata columns capability in gRPC health An engine whose writes fill the indexed metadata key columns reports the gRPC health service `weed.vector.capability.metadata_columns` as serving, so an operator action can refuse to index a key while an older engine could still write the table. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * vector: expire filter stats' operand kinds and truncation with the window The operand kinds a key was compared with, and the mark that a key went uncounted, outlived the queries that set them. Keep the kinds per 5-minute bucket and the truncation as the bucket it last happened in, so both leave the hour window with the counts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * vector: fill indexed key columns a write left empty racing their add A PutVectors that opened the table before an indexed key's column was added, and commits after the add, is rebased by Lance onto the wider schema: it commits, and the rows it wrote hold NULL in the new column, so the column's index misses them (reproduced in the test: 100 of 150 rows). After its commit, PutVectors now looks for indexed-key columns the batch did not carry, reads those of its keys whose column is still NULL, derives the values from their stored metadata and patches just those columns with a partial-schema merge that updates only rows still NULL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * vector: keep filter stats' truncation mark at the later bucket record() reads the clock before it takes the lock, so a call that waited on the lock across a bucket boundary could move the truncation mark (and the index's last-used bucket) back to its earlier bucket, and the mark then left the window one bucket early. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * vector: derive a raced write's indexed key columns from current metadata A PutVectors that opened the table before an indexed key's column was added is retried by Lance against the wider schema: rows it inserts hold NULL there, and rows it updates keep the value derived from their old metadata, which the NULL-only heal never looked at. The heal now derives the columns for all of the write's keys. Its merge also ran with Lance's retry, which joins the values derived before the conflict onto the rows a later write of the same keys left. It now fails on a conflict and is redone from the latest version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * vector: check the raced write's keys keep the later write's rows Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
170 lines
4.4 KiB
Protocol Buffer
170 lines
4.4 KiB
Protocol Buffer
syntax = "proto3";
|
|
|
|
package vector_pb;
|
|
|
|
option go_package = "github.com/seaweedfs/seaweedfs/weed/pb/vector_pb";
|
|
|
|
import "google/protobuf/struct.proto";
|
|
|
|
// The shared contract between the Go S3 gateway and the vector query engine.
|
|
// The public S3 Vectors API stays an AWS contract; this RPC is the internal
|
|
// boundary the design doc gives both editions.
|
|
service VectorService {
|
|
rpc CreateIndex(CreateIndexRequest) returns (CreateIndexResponse);
|
|
rpc DropIndex(DropIndexRequest) returns (DropIndexResponse);
|
|
rpc PutVectors(PutVectorsRequest) returns (PutVectorsResponse);
|
|
rpc GetVectors(GetVectorsRequest) returns (GetVectorsResponse);
|
|
rpc DeleteVectors(DeleteVectorsRequest) returns (DeleteVectorsResponse);
|
|
rpc ListVectors(ListVectorsRequest) returns (ListVectorsResponse);
|
|
rpc QueryVectors(QueryVectorsRequest) returns (QueryVectorsResponse);
|
|
// How this engine's queries of an index filtered on each metadata key
|
|
// over the last hour.
|
|
rpc FilterStats(FilterStatsRequest) returns (FilterStatsResponse);
|
|
}
|
|
|
|
enum DistanceMetric {
|
|
DISTANCE_METRIC_UNSPECIFIED = 0;
|
|
L2 = 1;
|
|
COSINE = 2;
|
|
DOT_PRODUCT = 3;
|
|
}
|
|
|
|
// Table addresses a Lance table through the namespace: the id parts as the
|
|
// namespace catalog joins them. The gateway resolves the table before it
|
|
// calls, so the engine opens it without a catalog round trip of its own.
|
|
message Table {
|
|
repeated string id = 1;
|
|
// Dataset version to pin reads to; 0 means latest.
|
|
uint64 version = 2;
|
|
// The table's Lance location, as the catalog describes it.
|
|
string location = 3;
|
|
reserved 4;
|
|
reserved "storage_options";
|
|
// The bucket encrypts its objects with SSE-S3; the engine writes the
|
|
// table's files that way.
|
|
bool sse_s3 = 5;
|
|
}
|
|
|
|
message CreateIndexRequest {
|
|
Table table = 1;
|
|
uint32 dimension = 2;
|
|
DistanceMetric distance_metric = 3;
|
|
repeated string non_filterable_metadata_keys = 4;
|
|
}
|
|
|
|
message CreateIndexResponse {
|
|
uint64 version = 1;
|
|
}
|
|
|
|
message DropIndexRequest {
|
|
Table table = 1;
|
|
}
|
|
|
|
message DropIndexResponse {}
|
|
|
|
message Vector {
|
|
string key = 1;
|
|
repeated float data = 2;
|
|
// JSON-typed metadata: numbers carry double precision, as on the wire.
|
|
google.protobuf.Struct metadata = 3;
|
|
}
|
|
|
|
message PutVectorsRequest {
|
|
Table table = 1;
|
|
repeated Vector vectors = 2;
|
|
}
|
|
|
|
message PutVectorsResponse {
|
|
uint64 version = 1;
|
|
}
|
|
|
|
message GetVectorsRequest {
|
|
Table table = 1;
|
|
repeated string keys = 2;
|
|
bool return_data = 3;
|
|
bool return_metadata = 4;
|
|
}
|
|
|
|
message GetVectorsResponse {
|
|
repeated Vector vectors = 1;
|
|
}
|
|
|
|
message DeleteVectorsRequest {
|
|
Table table = 1;
|
|
repeated string keys = 2;
|
|
}
|
|
|
|
message DeleteVectorsResponse {
|
|
uint64 version = 1;
|
|
}
|
|
|
|
message ListVectorsRequest {
|
|
Table table = 1;
|
|
uint32 max_results = 2;
|
|
string next_token = 3;
|
|
bool return_data = 4;
|
|
bool return_metadata = 5;
|
|
// A nonzero segment_count lists only the rows whose position modulo
|
|
// segment_count is segment_index; next_token stays a row position.
|
|
uint32 segment_count = 6;
|
|
uint32 segment_index = 7;
|
|
}
|
|
|
|
message ListVectorsResponse {
|
|
repeated Vector vectors = 1;
|
|
string next_token = 2;
|
|
// Set when segment_count was applied; an older engine ignores it.
|
|
bool segmented = 3;
|
|
}
|
|
|
|
message QueryVectorsRequest {
|
|
Table table = 1;
|
|
repeated float query_vector = 2;
|
|
uint32 top_k = 3;
|
|
// Lance SQL filter; empty means unfiltered. Metadata is one JSON
|
|
// `metadata` column, so the gateway translates S3 Vectors filter
|
|
// expressions onto it before they land here.
|
|
string filter = 4;
|
|
// Lance's post-filter escape hatch; off prefilters, matching S3 Vectors.
|
|
bool postfilter = 5;
|
|
bool return_metadata = 6;
|
|
bool return_distance = 7;
|
|
bool return_data = 8;
|
|
}
|
|
|
|
message QueryResult {
|
|
string key = 1;
|
|
float distance = 2;
|
|
google.protobuf.Struct metadata = 3;
|
|
repeated float data = 4;
|
|
}
|
|
|
|
message QueryVectorsResponse {
|
|
repeated QueryResult vectors = 1;
|
|
}
|
|
|
|
message FilterStatsRequest {
|
|
// Only the id is read.
|
|
Table table = 1;
|
|
}
|
|
|
|
message FilterKeyStats {
|
|
string key = 1;
|
|
uint64 queries = 2;
|
|
// Their total latency.
|
|
double seconds = 3;
|
|
// The operand types the key was compared with.
|
|
bool string_operand = 4;
|
|
bool number_operand = 5;
|
|
bool bool_operand = 6;
|
|
}
|
|
|
|
message FilterStatsResponse {
|
|
repeated FilterKeyStats keys = 1;
|
|
// The stats cover at most this long, less when the engine started later.
|
|
uint32 window_seconds = 2;
|
|
// Keys of this index not counted because the engine tracks a bounded
|
|
// number of them.
|
|
bool truncated = 3;
|
|
}
|