Skip to main content

JSON Type Definitions

CyborgDB provides strongly-typed JSON types for improved type safety when working with metadata and other JSON-serializable data.

JsonPrimitive

Represents any valid JSON primitive value.

JsonValue

Represents any valid JSON value. This is a recursive type definition used for metadata and other JSON-serializable data throughout the SDK.

JsonObject

Represents a JSON object with string keys and JsonValue values.

JsonArray

Represents a JSON array containing any valid JSON values.

VectorMetadata

Type alias for metadata associated with vector items. Metadata must be a valid JSON object.

Example Usage


CreateIndexRequest

The CreateIndexRequest interface defines the parameters for creating a new encrypted index.

Properties

Example Usage

v0.17 removed the polymorphic indexConfig and the associated IndexIVFFlat / IndexIVFPQ / IndexIVFSQ model types — there is now a single DiskIVF index type. Configuration parameters are flat fields on CreateIndexRequest.
The createIndex() method on the Client class accepts a Uint8Array for indexKey and automatically converts it to a hex-encoded string for the request. The CreateIndexRequest model itself uses the hex-encoded string type.

UpsertRequest

Interface for adding or updating vectors in an encrypted index.

Properties

Example Usage


QueryRequest

Interface for performing similarity search in the encrypted index.

Properties

Example Usage


BatchQueryRequest

Interface for performing batch similarity searches with multiple vectors.

Properties

Example Usage


TrainRequest

Interface for training an index to optimize query performance.

Properties

Example Usage


DeleteRequest

Interface for deleting vectors from the encrypted index.

Properties

Example Usage


GetRequest

Interface for retrieving specific vectors from the index.

Properties

Example Usage


VectorItem

Class representing a vectorized item for storage in the encrypted index.

Properties

Example Usage


Index Configuration

v0.17 introduces a single DiskIVF index type. The polymorphic IndexIVFFlat / IndexIVFPQ / IndexIVFSQ interfaces have been removed — there is no IndexConfig discriminated-union type any more. Configuration is expressed as flat fields on CreateIndexRequest / Client.createIndex().

Key Management

At least one of indexKey / kmsName must be supplied. Supplying both against a real-KMS slot is rejected by the server.

Response Types

UpsertResponse

Response interface for upsert operations.

Properties

Example Usage

DeleteResponse

Response interface for delete operations.

Properties

Example Usage

TrainResponse

Response interface for training operations.

Properties

Example Usage

HealthResponse

Response interface for health check operations.

Properties

Example Usage

Training status

There is no public TrainingStatus type in v0.17. Use index.isTraining() on an EncryptedIndex instance — it returns a Promise<boolean> indicating whether this index is currently being trained (or queued for training) on the server.
Internally, this calls the global /v1/indexes/training-status endpoint and tests whether the index name is in the returned trainingIndexes list. The full server-side response shape (trainingIndexes, retrainThreshold, currentlyTraining, queuedIndexes, workerRunning) is the OpenAPI-generated IndexTrainingStatusResponseModel and is not part of the SDK’s public surface.

GetResponseModel

Response class for vector retrieval operations.

Properties

GetResultItem

Enhanced type-safe result item for get operations. This type extends GetResultItemModel with proper typing for metadata and contents fields.

Properties

Example Usage

QueryResponse

Response class for similarity search operations.

Properties

Example Usage

QueryResultItem

Class representing a single result from similarity search.

Properties


Error Types

ErrorResponseModel

Standard error response class for API errors.

Properties

HTTPValidationError

Class for validation errors with detailed field information.

Properties


Metadata Filtering

The filters 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

For more information on metadata filtering, see Metadata Filtering.

Field Selection

Many operations support field selection through the include parameter:

Available Fields

  • vector: The vector data itself
  • contents: Text or binary content associated with the vector
  • metadata: Structured metadata object
  • distance: Similarity distance (query operations only)

Example Usage

Selecting only necessary fields improves performance by reducing data transfer and processing overhead.

Filter Types

FilterExpression

Type for constructing MongoDB-style filter expressions for querying vectors. Supports nested logical operators and field comparisons.

FilterValue

Represents possible filter values in filter expressions - can be any JSON primitive or array.

FilterOperator

Interface defining MongoDB-style query operators for metadata filtering. See the Metadata Filtering section for detailed examples.

Example Usage


Utility Functions

The SDK provides type guard and utility functions for safer type checking and error handling.

isJsonValue

Type guard function to check if a value is a valid JSON value. Handles circular references by tracking visited objects.

Parameters

Returns

boolean: Returns true if the value is a valid JSON value, false otherwise.

Example Usage

isError

Type guard to check if an error is an Error instance.

Parameters

Returns

boolean: Returns true if the value is an Error instance, false otherwise.

Example Usage

getErrorMessage

Helper function to safely extract error messages from unknown error types.

Parameters

Returns

string: A string message extracted from the error. Returns the error’s message property if it’s an Error, converts to string otherwise.

Example Usage