VectorsDB documents and queries
VectorsDB provides a document store for data that can be found with structured filters or vector similarity queries. It lets an application create, read, update, delete, and list documents in a collection, then group changes into transactions when several operations must succeed together. See Data, files, and execution services for the wider service map and Databases and TablesDB records for other structured data. See Queries, permissions, and roles for the shared access and query model.
Document model
Collection scope
The VectorsDB service addresses each document through a database ID, collection ID, and document ID. A collection must exist before document use, and its attributes define the shape of data that the service can store. The SDK exposes VectorsDB as the service entry point and exports it from the package root.
References: src/…/vectors-db.ts• L6-9 src/…/vectors-db.ts• L538-559 src/…/vectors-db.ts• L712-735
Document records
A document combines application data with service metadata. The metadata includes its identity, collection and database scope, creation and update times, and permissions. List responses return the matching documents and a total count; callers can use a typed document model or the default open data shape.
References: src/models.ts• L21-32 src/models.ts• L248-278 src/…/vectors-db.ts• L681-709
Document lifecycle
Document discovery
Listing finds documents in one collection and can apply query strings, read staged changes through a transaction, control total-count work, and set a cache lifetime for select queries. A known document can be read by ID, with the same query and transaction context available for that read.
The service offers a GET list path for normal query sizes and a POST query path when the query list is too large for a URL. The two list forms return the same document-list result.
References: src/…/vectors-db.ts• L538-710 src/…/vectors-db.ts• L911-1086 src/…/vectors-db.ts• L1088-1242
Document creation
Creation adds a new document with a chosen ID, JSON data, and optional permissions. The document ID can be custom or generated by the SDK's ID helper, but it must use the service's allowed character and length rules. A transaction ID changes creation from an immediate change into a staged operation.
References: src/…/vectors-db.ts• L712-735 src/…/vectors-db.ts• L826-908
Document modification
VectorsDB separates full replacement semantics from partial update semantics. Upsert creates a document or replaces the addressed document with the supplied data, while update changes only the supplied fields. Both can carry new permissions and can be staged in a transaction.
References: src/…/vectors-db.ts• L1244-1268 src/…/vectors-db.ts• L1360-1438 src/…/vectors-db.ts• L1441-1465 src/…/vectors-db.ts• L1557-1635
Document deletion
Deletion removes one document from its collection and returns no document body. Passing a transaction ID stages the removal so that it follows the transaction's final commit or rollback decision.
References: src/…/vectors-db.ts• L1638-1653 src/…/vectors-db.ts• L1709-1759
Query construction
Query strings
Query is the SDK helper for building the JSON strings accepted by VectorsDB query parameters. Each query names a method and can carry an attribute and values. The service accepts an array of these strings so callers can combine filters with ordering, field selection, and page controls.
References: src/query.ts• L4-37 src/…/vectors-db.ts• L538-559 src/…/vectors-db.ts• L911-933
Structured filters
Structured filters narrow documents by value, text, presence, range, array content, or dates. Logical and and or queries combine existing query strings, while selection, ordering, cursor, limit, and offset queries shape the result rather than change which data is stored.
References: src/query.ts• L40-144 src/query.ts• L155-227 src/query.ts• L230-297
Vector similarity
Vector similarity queries compare a stored vector attribute with a supplied number array. The SDK supports dot-product, cosine, and Euclidean comparisons. These queries belong in the same query list as ordinary filters, so an application can narrow the candidate documents and then apply a similarity condition in one search request.
References: src/query.ts• L389-423 src/…/vectors-db.ts• L538-559 src/…/vectors-db.ts• L911-933
Query result controls
The list and POST query requests use the same result controls. total: false avoids calculating a total when the caller only needs the page, and ttl gives eligible select queries a cache lifetime from zero to one day. A transaction ID makes the query see uncommitted changes from that transaction.
References: src/…/vectors-db.ts• L538-559 src/…/vectors-db.ts• L911-933 src/…/vectors-db.ts• L627-669 src/…/vectors-db.ts• L1002-1044
Atomic updates
Numeric operators
Operator creates JSON strings for changes that the service applies to the current document value. Numeric operators increment, decrement, multiply, divide, apply modulo, or raise a value to a power. Increment and decrement can include a maximum or minimum bound, which keeps a change within a caller-defined limit without a separate read and write.
These operator strings are passed as values inside document update data. The update request can therefore combine ordinary field changes with an atomic numeric change and can still use a transaction ID when the change belongs to a larger unit of work.
References: src/operator.ts• L17-51 src/operator.ts• L54-175 src/…/vectors-db.ts• L1441-1465 src/…/vectors-db.ts• L1557-1635 src/index.ts• L24-30
Numeric input guards
The SDK rejects non-finite numeric values before it creates an operator string. It also rejects zero as the divisor for divide and modulo. These checks protect the service from invalid arithmetic requests, while the stored attribute still needs to support the requested numeric operation.
References: src/operator.ts• L61-94 src/operator.ts• L103-155
Transactions
Transaction stages
A transaction is a temporary group of document operations with an expiration time. The caller creates it, stages document writes by passing its ID, and can add several operation descriptions through the batch operation endpoint. Reads that pass the same ID can see the transaction's uncommitted changes.
This diagram shows the transaction path from staged work to one final outcome.
flowchart LR
A[Create transaction] --> B[Stage document changes]
B --> C[Read with transaction ID]
C --> D{Final decision}
D -->|Commit| E[Committed changes]
D -->|Rollback| F[Discarded changes]
B --> G[Add multiple operations]
G --> D
References: src/…/vectors-db.ts• L11-185 src/…/vectors-db.ts• L187-377 src/…/vectors-db.ts• L440-536 src/…/vectors-db.ts• L538-669
Transaction outcomes
The transaction resource reports an ID, timestamps, operation count, expiration time, and a status. Its status moves through the service's transaction states, including pending, committing, committed, rolled back, or failed. The caller finalizes the work by requesting commit or rollback, can inspect transactions across databases, and can delete a transaction when it no longer needs to be retained.
References: src/models.ts• L205-214 src/models.ts• L1155-1177 src/…/vectors-db.ts• L11-110 src/…/vectors-db.ts• L113-437
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the database, collection, and document identity rules aligned across list, query, create, read, update, and delete operations.
- Keep the GET and POST query paths aligned when query limits, transaction visibility, total-count behavior, or cache rules change.
- Keep every vector query method's serialized shape aligned with the query strings accepted by VectorsDB.
- Keep operator validation and the document update data contract aligned when adding or changing atomic numeric operations.
- Keep transaction staging, transaction-aware reads, batch operation payloads, and commit or rollback behavior aligned.
- Keep the transaction status values in
Models.Transactionaligned with the states returned by the service.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The database ID, collection ID, or document ID is missing | The service cannot identify the document scope and rejects the request | Treat the full document identity as required for each operation that addresses a document |
| A collection is missing or its attributes do not support the document data | Creation or update fails before the expected document is available | Create the collection and define its attributes before writing documents |
| A query string is built with the wrong method, attribute, or value shape | Filtering or vector similarity returns an error or the wrong result set | Build query strings with Query and keep vector values as number arrays |
| A query list is too large for a URL | A GET list request cannot carry the intended search | Use the POST query form for larger query arrays |
An operator receives NaN, infinity, or a zero divisor | The SDK throws before sending the update | Use finite values and a non-zero divisor; use bounds for safe increment or decrement limits |
| A transaction expires or is finalized with the wrong outcome | Staged changes are not committed as intended | Track the transaction ID and expiry, then explicitly commit or roll back the intended work |
| A read omits the transaction ID | The response does not include the transaction's uncommitted changes | Pass the same transaction ID to reads that must observe staged state |
Key files
| File | Why to read it |
|---|---|
| src/…/vectors-db.ts | Defines the VectorsDB service contract for document CRUD, query requests, transaction staging, batch operations, and transaction control. |
| src/query.ts | Defines the JSON query strings used for filters, result shaping, pagination, and vector similarity. |
| src/operator.ts | Defines atomic update strings and the numeric input checks used by document updates. |
| src/models.ts | Defines the document, document-list, and transaction response shapes. |
| src/index.ts | Shows the public package exports for VectorsDB, Query, and Operator. |