Cortex

API Reference

Schemas

Effect Schema definitions for Cortex data models, queries, and errors.

Cortex uses Effect Schema for all its data structures, providing runtime validation and type safety.

Core Types

DocumentId

A branded string used to uniquely identify documents in the database.

import { DocumentId } from "@thaletto/cortex"

const id = DocumentId.make("user-123")

Vector

A branded Array<number> representing the embedding vector. The length must match the dimension configured in your adapter.

import { Vector } from "@thaletto/cortex"

const vector = Vector.make([0.1, 0.2, ...])

Data Models

CollectionSchema

The internal representation of a document stored in the database.

FieldTypeDescription
idDocumentIdUnique identifier
contentstringThe text content
categorystringIndexable category
tagsstring[]Indexable tags
metadata_jsonstringArbitrary JSON metadata
created_atDateInsertion timestamp
expires_atDateTTL expiration timestamp

UpsertPayload

The input structure for upsert and upsertMany operations.

FieldTypeDescription
idDocumentIdUnique identifier
contentstringThe text content to store
categorystringCategory for filtering
tagsstringSingle string (converted to array internally)
metadata_jsonstringJSON string for extra data
vectorVectorThe embedding vector
expires_atDateWhen this record should expire

SearchResult

Returned by the search method.

interface SearchResult {
  readonly document: CollectionSchema
  readonly score: number // 0 to 1 (similarity)
}

Query Types

QueryFilter

Used to filter documents during search, list, or delete operations.

FieldTypeDescription
categorystring (optional)Match documents in this category
tagsstring[] (optional)Match if any of these tags are present
activeAtDate (optional)Only include docs expiring after this date

Pagination

Used to paginate results in the list method.

interface Pagination {
  readonly limit: number
  readonly offset: number
}

Errors

All errors in Cortex are TaggedError classes.

VectorDBError

Generic storage or adapter error.

  • message: string
  • cause: unknown (optional)

DocumentNotFound

Thrown when an operation expects a document to exist (e.g., getById, delete).

  • id: DocumentId

DimensionMismatch

Thrown when a provided vector's length does not match the configured dimension.

  • expected: number
  • actual: number

On this page