import { z } from 'zod'; import { e as GraphDef, a3 as VectorSlot } from './types-BynPp5kU.js'; /** * Embedding type for vector search. * * Creates a Zod-compatible schema for vector embeddings with * dimension validation and metadata for query compilation. */ /** * Symbol used to brand embedding values at the type level. * This allows TypeScript to distinguish embedding arrays from regular * number arrays in the query builder type system. */ declare const EMBEDDING_BRAND: unique symbol; /** * Branded embedding type for type-level distinction. * At runtime this is just `readonly number[]`, but TypeScript can * distinguish it from regular arrays for query builder typing. */ type EmbeddingValue = readonly number[] & { readonly [EMBEDDING_BRAND]: true; }; /** * Symbol key for storing embedding dimensions on the schema. * This allows the schema introspector to detect embedding types * and extract dimension information. */ declare const EMBEDDING_DIMENSIONS_KEY: "_embeddingDimensions"; /** * Symbol key for storing the embedding's preferred index configuration * on the schema. The schema introspector reads this when auto-deriving * `VectorIndexDeclaration` entries at `defineGraph()` time. */ declare const EMBEDDING_INDEX_KEY: "_embeddingIndex"; /** * Distance metric used for vector similarity. Pinned at the embedding * brand because changing the metric usually means generating different * model output (e.g. cosine-normalized vs. raw inner-product), and the * stored index needs the same metric to score correctly. * * - `cosine`: cosine similarity. The default — works for most * sentence-transformer / OpenAI-style embeddings that are already * length-normalized. * - `l2`: Euclidean distance. Use when your model outputs vectors * trained for L2 (e.g. some image embedding models). * - `inner_product`: dot-product distance. Use when your model outputs * pre-normalized vectors AND you want to skip the cosine * normalization step at query time. */ type EmbeddingMetric = "cosine" | "l2" | "inner_product"; /** * Vector index implementation. `hnsw` is the default and what pgvector * recommends for most workloads. `ivfflat` is the alternative for * larger datasets where memory is the bottleneck. `none` disables * automatic index creation for this embedding (the operator can still * call `backend.createVectorIndex` manually). */ type EmbeddingIndexType = "hnsw" | "ivfflat" | "none"; /** * Per-embedding configuration for the auto-derived * `VectorIndexDeclaration`. All fields are optional with sensible * defaults (`cosine` / `hnsw` / pgvector defaults: `m=16`, * `ef_construction=64`). Override only when your model or dataset has * a known reason to. */ type EmbeddingIndexOptions = Readonly<{ /** Distance metric. Default `"cosine"`. */ metric?: EmbeddingMetric; /** Vector index implementation. Default `"hnsw"`. */ indexType?: EmbeddingIndexType; /** HNSW `m` parameter — max connections per layer. Default `16`. */ m?: number; /** HNSW `ef_construction` parameter — build-time search depth. Default `64`. */ efConstruction?: number; /** IVFFlat `lists` parameter — number of inverted-list partitions. */ lists?: number; }>; /** * Resolved embedding index configuration with all defaults applied. * What gets attached to the brand and read by the auto-derivation pass. */ type ResolvedEmbeddingIndex = Readonly<{ metric: EmbeddingMetric; indexType: EmbeddingIndexType; m: number; efConstruction: number; lists: number | undefined; }>; /** * A Zod schema for vector embeddings with attached dimension metadata. * Uses the branded EmbeddingValue type for type-level distinction. */ type EmbeddingSchema = z.ZodType & Readonly<{ [EMBEDDING_DIMENSIONS_KEY]: D; [EMBEDDING_INDEX_KEY]: ResolvedEmbeddingIndex; }>; /** * Creates a Zod schema for vector embeddings. * * The dimension is validated at runtime and attached as metadata * for the schema introspector and query compiler. * * @param dimensions - The number of dimensions (e.g., 384, 512, 768, 1536, 3072) * @returns A Zod schema that validates embedding arrays * * @example * ```typescript * // OpenAI ada-002 embeddings * const Document = defineNode("Document", { * schema: z.object({ * title: z.string(), * embedding: embedding(1536), * }), * }); * * // Sentence transformers * const Sentence = defineNode("Sentence", { * schema: z.object({ * text: z.string(), * embedding: embedding(384), // all-MiniLM-L6-v2 * }), * }); * * // Optional embeddings are supported * const Article = defineNode("Article", { * schema: z.object({ * content: z.string(), * embedding: embedding(1536).optional(), * }), * }); * ``` */ declare function embedding(dimensions: D, options?: EmbeddingIndexOptions): EmbeddingSchema; /** * Checks if a value is an embedding schema. */ declare function isEmbeddingSchema(value: unknown): value is EmbeddingSchema; /** * Gets the dimensions from an embedding schema. * Returns undefined if the schema is not an embedding schema. */ declare function getEmbeddingDimensions(schema: z.ZodType): number | undefined; /** * Enumerates every embedding `(kind, field)` slot a graph declares, as a * fully-resolved {@link VectorSlot}. The single source of truth for "what * vector slots does this graph have?", shared by the privileged boot * materializer (`materializeVectorContributions`) and the verified-attach * gate (`assertVectorContributionsInitialized`) so the two can never * provision and assert different sets. Walks `graph.nodes` and reuses * {@link resolveEmbeddingFields} per node schema. */ declare function resolveGraphVectorSlots(graph: GraphDef): readonly VectorSlot[]; /** * Searchable string type for fulltext search. * * `searchable()` attaches `SearchableMetadata` to a plain Zod string so * the schema introspector and fulltext-sync layer can keep the fulltext * index in sync with node data. * * The metadata is preserved by Zod's `.meta()` across refinements * (`.min(1)`, `.trim()`, `.regex(...)`) and wrapper types (`.optional()`, * `.nullable()`, `.default(...)`, pipes) — `getSearchableMetadata()` walks * these variants so runtime indexing works whether or not a user chains * additional modifiers. * * `$fulltext` is exposed on every `NodeAccessor` at the type level; a * runtime guard throws a clear error if you call `.matches()` on an * alias whose node kind has no `searchable()` fields. This is simpler * and more predictable than a type-level brand that silently disappears * behind `.min(1)`. * * @example * ```typescript * const Document = defineNode("Document", { * schema: z.object({ * title: searchable({ language: "english" }), * body: searchable().min(1), * authorId: z.string(), * }), * }); * ``` */ declare const SEARCHABLE_FIELD_KEY: "_searchableField"; declare const DEFAULT_SEARCHABLE_LANGUAGE: "english"; /** * Searchable field metadata attached to a Zod schema. */ type SearchableMetadata = Readonly<{ /** * Language for stemming / tokenization. * Postgres: passed to `to_tsvector(regconfig, ...)`. * SQLite FTS5: tokenizer is fixed at table-create time, so the * language is recorded but not applied per-row. */ language: string; }>; /** * Branded Zod string schema. The `SEARCHABLE_FIELD_KEY` marker is * attached both as a direct property (fast runtime check) and via Zod's * `.meta()` (so it survives `.min()`, `.trim()`, etc.). */ type SearchableSchema = z.ZodString & Readonly<{ [SEARCHABLE_FIELD_KEY]: SearchableMetadata; }>; type SearchableOptions = Readonly<{ language?: string; }>; /** * Creates a Zod string schema tagged as fulltext-searchable. * * The returned schema passes runtime validation unchanged — the tag only * affects how TypeGraph treats the field for indexing and search. Pair * with `.optional()` / `.nullable()` / `.min()` / `.trim()` exactly like * any other Zod string; `getSearchableMetadata()` finds the metadata * through all of them. */ declare function searchable(options?: SearchableOptions): SearchableSchema; declare function isSearchableSchema(value: unknown): value is SearchableSchema; declare function getSearchableMetadata(schema: z.ZodType): SearchableMetadata | undefined; export { DEFAULT_SEARCHABLE_LANGUAGE as D, type EmbeddingMetric as E, type SearchableMetadata as S, type EmbeddingIndexType as a, type EmbeddingSchema as b, type EmbeddingValue as c, type SearchableOptions as d, type SearchableSchema as e, embedding as f, getEmbeddingDimensions as g, getSearchableMetadata as h, isEmbeddingSchema as i, isSearchableSchema as j, resolveGraphVectorSlots as r, searchable as s };