Skip to content

API reference

vector(options) creates a Layeron Vector index backed by Cloudflare Vectorize.

Terminal window
import { vector } from "@layeron/modules"

Create a Vector index backed by Cloudflare Vectorize.

Terminal window
vector(options: VectorOptions): VectorModule

One metadata field indexed for Vector query filters.

FieldTypeDescription
propertyNamestringMetadata property name.
typeVectorMetadataIndexTypeMetadata property type.

Metadata indexing options for a Vector index.

FieldTypeDescription
indexesVectorMetadataIndex[] | undefinedMetadata fields indexed for filtering.

Options accepted by vector(options).

FieldTypeDescription
namestringStable Vector index name inside the Layeron app.
namespacestring | undefinedPlatform namespace for the instance. Defaults to default.
bindingstring | undefinedWorker binding name. Omit to let Layeron derive a stable binding.
dimensionsint32Number of dimensions in each vector.
metricVectorMetric | undefinedSimilarity metric. Omit to use cosine.
metadataVectorMetadataOptions | undefinedMetadata indexing options.

Normalized Vector module configuration.

FieldTypeDescription
kind”vector”Module config kind.
namestringStable Vector index name inside the Layeron app.
namespacestringPlatform namespace for the instance. Defaults to default.
bindingstringWorker binding name.
dimensionsint32Number of dimensions in each vector.
metricVectorMetricSimilarity metric.
metadataVectorMetadataOptions | undefinedMetadata indexing options.

One vector record stored in the index.

FieldTypeDescription
idstringApplication-defined vector id.
valuesfloat32[]Embedding values. Length must match the index dimensions.
metadataRecord<unknown> | undefinedMetadata stored with the vector record.

Result returned after a vector mutation.

FieldTypeDescription
countint32Number of records accepted by the mutation.
idsstring[]Vector ids accepted by the mutation.

Query options shared by vector search operations.

FieldTypeDescription
topKint32 | undefinedMaximum matches to return.
filterRecord<unknown> | undefinedMetadata filter expression.
returnValuesboolean | undefinedWhether matching vector values are returned.
returnMetadataboolean | undefinedWhether matching metadata is returned.

Input accepted by index.query(input).

FieldTypeDescription
vectorfloat32[]Query vector. Length must match the index dimensions.

One vector match returned by a query.

FieldTypeDescription
idstringMatched vector id.
scorefloat32Similarity score returned by Vectorize.
valuesfloat32[] | undefinedVector values when returnValues is true.
metadataRecord<unknown> | undefinedVector metadata when returnMetadata is true.

Result returned by index.query(input).

FieldTypeDescription
matchesVectorMatch[]Ordered vector matches.
countint32Number of matches returned.

Index description returned by index.describe().

FieldTypeDescription
namespacestringPlatform namespace for the instance. Defaults to default.
namestringStable Vector index name inside the Layeron app.
dimensionsint32Number of dimensions in each vector.
metricVectorMetricSimilarity metric.
bindingstringWorker binding name.

Layeron Vector module returned by vector(options).

FieldTypeDescription
name”vector”Module name.
configVectorModuleConfigNormalized module configuration.

Metadata field type supported by Vectorize metadata indexes.

ValueDescription
stringString metadata field.
numberNumber metadata field.
booleanBoolean metadata field.

Similarity metric used by the Vector index.

ValueDescription
cosineCosine similarity.
euclideanEuclidean distance.
dot_productDot product similarity.

Insert new vector records.

TypeSpec operation: vectorInsert.

Terminal window
index.insert(vectors: VectorRecord[]): VectorMutationResult

Insert or replace vector records.

TypeSpec operation: vectorUpsert.

Terminal window
index.upsert(vectors: VectorRecord[]): VectorMutationResult

Run a similarity search.

TypeSpec operation: vectorQuery.

Terminal window
index.query(input: VectorQueryInput): VectorQueryResult

Read vector records by id.

TypeSpec operation: vectorGet.

Terminal window
index.get(ids: string[]): VectorRecord[]

Delete vector records by id.

TypeSpec operation: vectorDelete.

Terminal window
index.delete(ids: string[]): VectorMutationResult

Return the Vector index configuration known to Layeron.

TypeSpec operation: vectorDescribe.

Terminal window
index.describe(): VectorDescribeResult