JSON Type Definitions
CyborgDB provides strongly-typed JSON types for improved type safety when working with metadata and other JSON-serializable data.JsonPrimitive
JsonValue
JsonObject
JsonArray
VectorMetadata
Example Usage
CreateIndexRequest
TheCreateIndexRequest interface defines the parameters for creating a new encrypted index.
Properties
| Parameter | Type | Required | Description |
|---|---|---|---|
indexConfig | IndexConfig | Yes | Configuration model specifying index type and parameters |
indexKey | Uint8Array | Yes | 32-byte encryption key |
indexName | string | Yes | Unique name/identifier for the index |
embeddingModel | string | null | No | Optional embedding model name for automatic vector generation |
Example Usage
UpsertRequest
Interface for adding or updating vectors in an encrypted index.Properties
| Parameter | Type | Required | Description |
|---|---|---|---|
items | VectorItem[] | Yes | Array of vector items to insert or update |
Example Usage
QueryRequest
Interface for performing similarity search in the encrypted index.Properties
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
queryVectors | number[] | number[][] | null | No | - | Vector(s) for similarity search |
queryContents | string | null | No | - | Text content for semantic search (requires embedding model) |
topK | number | No | undefined (server default: 100) | Number of nearest neighbors to return |
nProbes | number | No | undefined (auto) | Number of lists to probe during query. Auto-determined when undefined for optimal performance. |
greedy | boolean | No | false | Whether to use greedy search algorithm |
filters | object | null | No | undefined | JSON-like dictionary for metadata filtering (no filtering when undefined) |
include | string[] | No | undefined (server default: ["distance", "metadata"]) | Fields to include in response. Note: id is always included. |
Example Usage
BatchQueryRequest
Interface for performing batch similarity searches with multiple vectors.Properties
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
queryVectors | number[][] | Yes | - | Array of vectors for batch similarity search |
topK | number | No | undefined (server default: 100) | Number of nearest neighbors to return per query |
nProbes | number | No | undefined (auto) | Number of lists to probe during each query. Auto-determined when undefined. |
greedy | boolean | No | false | Whether to use greedy search algorithm |
filters | object | No | undefined | JSON-like dictionary for metadata filtering (no filtering when undefined) |
include | string[] | No | undefined (server default: ["distance", "metadata"]) | Fields to include in response. Note: id is always included. |
Example Usage
TrainRequest
Interface for training an index to optimize query performance.Properties
| Parameter | Type | Required | Description |
|---|---|---|---|
nLists | number | No | Number of inverted lists for indexing |
batchSize | number | No | Size of each batch for training |
maxIters | number | No | Maximum iterations for training |
tolerance | number | No | Convergence tolerance for training |
Example Usage
DeleteRequest
Interface for deleting vectors from the encrypted index.Properties
| Parameter | Type | Required | Description |
|---|---|---|---|
ids | string[] | Yes | Array of vector IDs to delete |
Example Usage
GetRequest
Interface for retrieving specific vectors from the index.Properties
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
ids | string[] | Yes | - | Array of vector IDs to retrieve |
include | string[] | No | ["vector", "contents", "metadata"] | Fields to include in response |
Example Usage
VectorItem
Class representing a vectorized item for storage in the encrypted index.Properties
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Unique identifier for the vector item |
vector | number[] | null | No* | Vector representation of the item. *Required for upsert operations unless using embedding model |
contents | string | null | No | Original text or associated content |
metadata | VectorMetadata | null | No | Additional structured metadata (must be valid JSON) |
Example Usage
Index Configuration Types
IndexIVF
Standard IVF (Inverted File) index configuration, ideal for balanced performance:| Speed | Accuracy | Memory Usage |
|---|---|---|
| Fast | Good | Medium |
Properties
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
type | 'ivf' | Yes | - | Index type identifier |
dimension | number | null | No | - | Dimensionality of vector embeddings |
Example Usage
IndexIVFFlat
IVFFlat index configuration, suitable for highest accuracy requirements:| Speed | Accuracy | Memory Usage |
|---|---|---|
| Medium | Highest | High |
Properties
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
type | 'ivfflat' | Yes | - | Index type identifier |
dimension | number | null | No | - | Dimensionality of vector embeddings |
Example Usage
IndexIVFPQ
IVFPQ (Product Quantization) index configuration, optimized for memory efficiency:| Speed | Accuracy | Memory Usage |
|---|---|---|
| Fast | Good | Low |
Properties
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
type | 'ivfpq' | Yes | - | Index type identifier |
pqDim | number | Yes | - | Dimensionality after quantization |
pqBits | number | Yes | - | Number of bits per quantizer (1-16) |
dimension | number | null | No | - | Dimensionality of vector embeddings |
Example Usage
Response Types
UpsertResponse
Response interface for upsert operations.Properties
| Parameter | Type | Description |
|---|---|---|
status | string | Status of the operation |
upsertedCount | number (optional) | Number of vectors upserted |
message | string (optional) | Additional message or details |
Example Usage
DeleteResponse
Response interface for delete operations.Properties
| Parameter | Type | Description |
|---|---|---|
status | string | Status of the operation |
deletedCount | number (optional) | Number of vectors deleted |
message | string (optional) | Additional message or details |
Example Usage
TrainResponse
Response interface for training operations.Properties
| Parameter | Type | Description |
|---|---|---|
status | string | Status of the training operation |
message | string (optional) | Additional message or details |
Example Usage
HealthResponse
Response interface for health check operations.Properties
| Parameter | Type | Description |
|---|---|---|
status | string | Status of the service |
[key: string] | string | Optional additional health information |
Example Usage
TrainingStatus
Response interface for training status queries.Properties
| Parameter | Type | Description |
|---|---|---|
training_indexes | string[] | Array of index names currently being trained |
retrain_threshold | number | The multiplier used for the retraining threshold |
Example Usage
GetResponseModel
Response class for vector retrieval operations.Properties
| Parameter | Type | Description |
|---|---|---|
results | GetResultItemModel[] | Array of retrieved items with requested fields |
GetResultItem
Enhanced type-safe result item for get operations. This type extendsGetResultItemModel with proper typing for metadata and contents fields.
Properties
| Parameter | Type | Description |
|---|---|---|
id | string | Unique identifier for the vector item |
vector | number[] (optional) | Vector data (if included in response) |
contents | Buffer | Blob | string (optional) | The original content |
metadata | VectorMetadata (optional) | Metadata associated with the vector |
Example Usage
QueryResponse
Response class for similarity search operations.Properties
| Parameter | Type | Description |
|---|---|---|
results | QueryResultItem[] | QueryResultItem[][] | Search results (flat array for single queries, nested array for batch queries) |
Example Usage
QueryResultItem
Class representing a single result from similarity search.Properties
| Parameter | Type | Description |
|---|---|---|
id | string | Identifier of the retrieved item |
distance | number | null | Distance from query vector (lower = more similar) |
metadata | object | null | Additional metadata for the result |
vector | number[] | null | Retrieved vector (if included in response) |
Error Types
ErrorResponseModel
Standard error response class for API errors.Properties
| Parameter | Type | Description |
|---|---|---|
statusCode | number | HTTP status code of the error |
detail | string | Detailed message describing the error |
HTTPValidationError
Class for validation errors with detailed field information.Properties
| Parameter | Type | Description |
|---|---|---|
detail | ValidationError[] | Array of validation errors with field details |
Metadata Filtering
Thefilters parameter in query operations supports a subset of MongoDB query operators for flexible metadata filtering:
Supported Operators
$eq: Equality ({ "category": "research" })$ne: Not equal ({ "status": { "$ne": "draft" } })$gt: Greater than ({ "score": { "$gt": 0.8 } })$gte: Greater than or equal ({ "year": { "$gte": 2020 } })$lt: Less than ({ "price": { "$lt": 100 } })$lte: Less than or equal ({ "rating": { "$lte": 4.5 } })$in: In array ({ "tag": { "$in": ["ai", "ml"] } })$nin: Not in array ({ "category": { "$nin": ["spam", "deleted"] } })$and: Logical AND ({ "$and": [{"a": 1}, {"b": 2}] })$or: Logical OR ({ "$or": [{"x": 1}, {"y": 2}] })
Filter Examples
Field Selection
Many operations support field selection through theinclude parameter:
Available Fields
vector: The vector data itselfcontents: Text or binary content associated with the vectormetadata: Structured metadata objectdistance: Similarity distance (query operations only)
Example Usage
Filter Types
FilterExpression
FilterValue
FilterOperator
Example Usage
Utility Functions
The SDK provides type guard and utility functions for safer type checking and error handling.isJsonValue
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
value | unknown | Yes | The value to check |
visited | WeakSet<object> | No | Internal parameter for tracking circular references |
Returns
boolean: Returns true if the value is a valid JSON value, false otherwise.
Example Usage
isError
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
error | unknown | Yes | The value to check |
Returns
boolean: Returns true if the value is an Error instance, false otherwise.
Example Usage
getErrorMessage
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
error | unknown | Yes | The error to extract a message from |
Returns
string: A string message extracted from the error. Returns the error’s message property if it’s an Error, converts to string otherwise.