{"version":3,"file":"factory.mjs","names":[],"sources":["../../../src/batteries/vector/factory.ts"],"sourcesContent":["/**\n * @module @nhtio/adk/batteries/vector/factory\n */\n\nimport { E_VECTOR_STORE_DRIVER_UNAVAILABLE } from './exceptions'\nimport { validateCreateConfig, resolveClientCtor } from './validation'\nimport type { CallableVectorStore, BaseVectorStore } from './contract'\nimport type { BaseVectorStoreOptions, VectorEncoderFn, EncodeKind } from './types'\n\n/** The adapter class shape the factory accepts as `client` — a constructor with an optional availability probe. */\nexport interface VectorStoreConstructor<O extends BaseVectorStoreOptions = BaseVectorStoreOptions> {\n  /** Construct the adapter from its options. */\n  new (options: O): BaseVectorStore\n  /** Optional static probe: `false` short-circuits creation with a driver-unavailable error. */\n  isAvailable?: () => boolean\n}\n\n/**\n * `client` is one of:\n *   - the adapter class itself          — `QdrantVectorStore`\n *   - a sync resolver                   — `() => QdrantVectorStore`\n *   - an async resolver / dynamic import — `() => import('…/qdrant').then(m => m.QdrantVectorStore)`\n * A resolver may also return a module namespace whose `default` is the class.\n */\nexport type VectorStoreClient<O extends BaseVectorStoreOptions = BaseVectorStoreOptions> =\n  | VectorStoreConstructor<O>\n  | (() => VectorStoreConstructor<O> | { default: VectorStoreConstructor<O> })\n  | (() => Promise<VectorStoreConstructor<O> | { default: VectorStoreConstructor<O> }>)\n\n/** Configuration accepted by {@link createVectorStore}: the adapter `client` plus its `options`. */\nexport interface CreateVectorStoreConfig<\n  O extends BaseVectorStoreOptions = BaseVectorStoreOptions,\n> {\n  /** The adapter class, or a (possibly async) resolver of it. See {@link VectorStoreClient}. */\n  client: VectorStoreClient<O>\n  /** Options passed to the resolved adapter's constructor. */\n  options: O\n}\n\n/**\n * Build a callable store. Validate config; resolve the `client` (class | sync resolver | async\n * resolver) to a BaseVectorStore subclass ctor; optional availability gate; construct; return\n * asCallable(). Async so that `client: () => import('…')` can lazily load the adapter (and its\n * driver) only when the store is actually created.\n */\nexport const createVectorStore = async <O extends BaseVectorStoreOptions = BaseVectorStoreOptions>(\n  config: CreateVectorStoreConfig<O>\n): Promise<CallableVectorStore> => {\n  validateCreateConfig(config)\n  const Ctor = (await resolveClientCtor(config.client)) as VectorStoreConstructor<O>\n  if (typeof Ctor.isAvailable === 'function' && !Ctor.isAvailable()) {\n    throw new E_VECTOR_STORE_DRIVER_UNAVAILABLE([Ctor.name || 'unknown'])\n  }\n  const instance = new Ctor(config.options)\n  return instance.asCallable() as CallableVectorStore\n}\n\n// Helper: adapt an embeddings-battery-shaped object (has embedMany(texts, { kind })) into a VectorEncoderFn.\n// The embeddings adapters expose: embedMany(texts: string[], opts?: { kind?: 'query'|'document' }): Promise<number[][]>\n/** The minimal shape of an embeddings-battery adapter usable as a vector encoder. */\nexport interface EmbeddingsLike {\n  /** Embed a batch of texts, optionally hinting query vs. document encoding. */\n  embedMany(texts: string[], opts?: { kind?: EncodeKind }): Promise<number[][]>\n}\n/**\n * Adapt an {@link EmbeddingsLike} object into a {@link VectorEncoderFn} for use as a store encoder.\n *\n * @param adapter - The embeddings adapter to wrap.\n * @returns An encoder function forwarding to `adapter.embedMany`.\n */\nexport const encoderFromEmbeddings = (adapter: EmbeddingsLike): VectorEncoderFn => {\n  return (texts: string[], kind: EncodeKind) => adapter.embedMany(texts, { kind })\n}\n"],"mappings":";;;;;;;;;;;;AA6CA,IAAa,oBAAoB,OAC/B,WACiC;CACjC,qBAAqB,MAAM;CAC3B,MAAM,OAAQ,MAAM,kBAAkB,OAAO,MAAM;CACnD,IAAI,OAAO,KAAK,gBAAgB,cAAc,CAAC,KAAK,YAAY,GAC9D,MAAM,IAAI,kCAAkC,CAAC,KAAK,QAAQ,SAAS,CAAC;CAGtE,OAAO,IADc,KAAK,OAAO,OAC1B,EAAS,WAAW;AAC7B;;;;;;;AAeA,IAAa,yBAAyB,YAA6C;CACjF,QAAQ,OAAiB,SAAqB,QAAQ,UAAU,OAAO,EAAE,KAAK,CAAC;AACjF"}