API reference
vector(options) creates a Layeron Vector index backed by Cloudflare Vectorize.
Import
Section titled “Import”import { vector } from "@layeron/modules"vector
Section titled “vector”Create a Vector index backed by Cloudflare Vectorize.
vector(options: VectorOptions): VectorModuleVectorMetadataIndex
Section titled “VectorMetadataIndex”One metadata field indexed for Vector query filters.
| Field | Type | Description |
|---|---|---|
propertyName | string | Metadata property name. |
type | VectorMetadataIndexType | Metadata property type. |
VectorMetadataOptions
Section titled “VectorMetadataOptions”Metadata indexing options for a Vector index.
| Field | Type | Description |
|---|---|---|
indexes | VectorMetadataIndex[] | undefined | Metadata fields indexed for filtering. |
VectorOptions
Section titled “VectorOptions”Options accepted by vector(options).
| Field | Type | Description |
|---|---|---|
name | string | Stable Vector index name inside the Layeron app. |
namespace | string | undefined | Platform namespace for the instance. Defaults to default. |
binding | string | undefined | Worker binding name. Omit to let Layeron derive a stable binding. |
dimensions | int32 | Number of dimensions in each vector. |
metric | VectorMetric | undefined | Similarity metric. Omit to use cosine. |
metadata | VectorMetadataOptions | undefined | Metadata indexing options. |
VectorModuleConfig
Section titled “VectorModuleConfig”Normalized Vector module configuration.
| Field | Type | Description |
|---|---|---|
kind | ”vector” | Module config kind. |
name | string | Stable Vector index name inside the Layeron app. |
namespace | string | Platform namespace for the instance. Defaults to default. |
binding | string | Worker binding name. |
dimensions | int32 | Number of dimensions in each vector. |
metric | VectorMetric | Similarity metric. |
metadata | VectorMetadataOptions | undefined | Metadata indexing options. |
VectorRecord
Section titled “VectorRecord”One vector record stored in the index.
| Field | Type | Description |
|---|---|---|
id | string | Application-defined vector id. |
values | float32[] | Embedding values. Length must match the index dimensions. |
metadata | Record<unknown> | undefined | Metadata stored with the vector record. |
VectorMutationResult
Section titled “VectorMutationResult”Result returned after a vector mutation.
| Field | Type | Description |
|---|---|---|
count | int32 | Number of records accepted by the mutation. |
ids | string[] | Vector ids accepted by the mutation. |
VectorQueryOptions
Section titled “VectorQueryOptions”Query options shared by vector search operations.
| Field | Type | Description |
|---|---|---|
topK | int32 | undefined | Maximum matches to return. |
filter | Record<unknown> | undefined | Metadata filter expression. |
returnValues | boolean | undefined | Whether matching vector values are returned. |
returnMetadata | boolean | undefined | Whether matching metadata is returned. |
VectorQueryInput
Section titled “VectorQueryInput”Input accepted by index.query(input).
| Field | Type | Description |
|---|---|---|
vector | float32[] | Query vector. Length must match the index dimensions. |
VectorMatch
Section titled “VectorMatch”One vector match returned by a query.
| Field | Type | Description |
|---|---|---|
id | string | Matched vector id. |
score | float32 | Similarity score returned by Vectorize. |
values | float32[] | undefined | Vector values when returnValues is true. |
metadata | Record<unknown> | undefined | Vector metadata when returnMetadata is true. |
VectorQueryResult
Section titled “VectorQueryResult”Result returned by index.query(input).
| Field | Type | Description |
|---|---|---|
matches | VectorMatch[] | Ordered vector matches. |
count | int32 | Number of matches returned. |
VectorDescribeResult
Section titled “VectorDescribeResult”Index description returned by index.describe().
| Field | Type | Description |
|---|---|---|
namespace | string | Platform namespace for the instance. Defaults to default. |
name | string | Stable Vector index name inside the Layeron app. |
dimensions | int32 | Number of dimensions in each vector. |
metric | VectorMetric | Similarity metric. |
binding | string | Worker binding name. |
VectorModule
Section titled “VectorModule”Layeron Vector module returned by vector(options).
| Field | Type | Description |
|---|---|---|
name | ”vector” | Module name. |
config | VectorModuleConfig | Normalized module configuration. |
VectorMetadataIndexType
Section titled “VectorMetadataIndexType”Metadata field type supported by Vectorize metadata indexes.
| Value | Description |
|---|---|
string | String metadata field. |
number | Number metadata field. |
boolean | Boolean metadata field. |
VectorMetric
Section titled “VectorMetric”Similarity metric used by the Vector index.
| Value | Description |
|---|---|
cosine | Cosine similarity. |
euclidean | Euclidean distance. |
dot_product | Dot product similarity. |
Operations
Section titled “Operations”index.insert
Section titled “index.insert”Insert new vector records.
TypeSpec operation: vectorInsert.
index.insert(vectors: VectorRecord[]): VectorMutationResultindex.upsert
Section titled “index.upsert”Insert or replace vector records.
TypeSpec operation: vectorUpsert.
index.upsert(vectors: VectorRecord[]): VectorMutationResultindex.query
Section titled “index.query”Run a similarity search.
TypeSpec operation: vectorQuery.
index.query(input: VectorQueryInput): VectorQueryResultindex.get
Section titled “index.get”Read vector records by id.
TypeSpec operation: vectorGet.
index.get(ids: string[]): VectorRecord[]index.delete
Section titled “index.delete”Delete vector records by id.
TypeSpec operation: vectorDelete.
index.delete(ids: string[]): VectorMutationResultindex.describe
Section titled “index.describe”Return the Vector index configuration known to Layeron.
TypeSpec operation: vectorDescribe.
index.describe(): VectorDescribeResult