/** * SochDB Namespace API * * Provides type-safe namespace isolation with first-class namespace handles. * * @example * ```typescript * import { Database } from '@sochdb/sochdb'; * * const db = await Database.open('./mydb'); * const ns = await db.createNamespace('tenant_123'); * const collection = await ns.createCollection('documents', { dimension: 384 }); * await collection.insert([1.0, 2.0, ...], { source: 'web' }); * const results = await collection.search(queryVector, 10); * ``` */ import { SochDBError } from './errors'; export interface NamespaceConfig { name: string; displayName?: string; labels?: Record; readOnly?: boolean; } export declare class NamespaceNotFoundError extends SochDBError { constructor(namespace: string); } export declare class NamespaceExistsError extends SochDBError { constructor(namespace: string); } export declare class CollectionNotFoundError extends SochDBError { constructor(collection: string); } export declare class CollectionExistsError extends SochDBError { constructor(collection: string); } export declare enum DistanceMetric { Cosine = "cosine", Euclidean = "euclidean", DotProduct = "dot" } export interface CollectionConfig { name: string; dimension?: number; metric?: DistanceMetric; indexed?: boolean; hnswM?: number; hnswEfConstruction?: number; metadata?: Record; } export interface SearchRequest { queryVector: number[]; k: number; filter?: Record; includeMetadata?: boolean; } export interface SearchResult { id: string; score: number; vector?: number[]; metadata?: Record; } export declare class Collection { private db; private namespace; private name; private config; private vectorIndex; private nativeIndexPtr; private _indexReady; private nativeIdCounter; private nativeIdToStringId; constructor(db: any, namespace: string, name: string, config: CollectionConfig); /** * Set ef_search parameter for HNSW search (controls recall vs speed tradeoff) * Higher values = better recall but slower search * @param efSearch - Typically 100-1000, default is 500 */ setEfSearch(efSearch: number): void; /** * Insert a vector with optional metadata * Vector is immediately indexed (synchronous) */ insert(vector: number[], metadata?: Record, id?: string): Promise; /** * Insert multiple vectors using NATIVE HNSW batch insert when available * This is the OPTIMIZED path - uses FFI batch insert for ~100x speedup */ insertMany(vectors: number[][], metadatas?: Record[], ids?: string[]): Promise; /** * Rebuild index from database (for recovery/startup) */ rebuildIndex(): Promise; /** * Check if index is ready (loaded from disk) */ get isIndexReady(): boolean; /** * Search for similar vectors. * Uses NATIVE HNSW search (O(log N)) when available, falls back to JS brute-force. * * Accepts either a {@link SearchRequest} object or a positional form * (`search(queryVector, k, { filter, includeMetadata })`) matching the * documented examples and the Python SDK. */ search(request: SearchRequest): Promise; search(queryVector: number[], k?: number, options?: { filter?: Record; includeMetadata?: boolean; }): Promise; /** * Get a vector by ID */ get(id: string): Promise<{ vector: number[]; metadata?: Record; } | null>; /** * Delete a vector by ID */ delete(id: string): Promise; /** * Count vectors in collection */ count(): Promise; private vectorKey; private vectorKeyPrefix; private metadataKey; private generateId; private cosineSimilarity; } export declare class Namespace { private db; private name; private config; constructor(db: any, name: string, config: NamespaceConfig); /** * Create a new collection in this namespace. * * Accepts either a single config object (`{ name, dimension, ... }`) or a * name-first form (`createCollection('docs', { dimension: 384 })`) to match * the documented examples and the Python SDK's `create_collection(name, ...)`. */ createCollection(config: CollectionConfig): Promise; createCollection(name: string, config?: Omit): Promise; /** * Get an existing collection */ collection(name: string): Promise; /** * Get or create a collection */ getOrCreateCollection(config: CollectionConfig): Promise; /** * Delete a collection */ deleteCollection(name: string): Promise; /** * List all collections in this namespace */ listCollections(): Promise; getName(): string; getConfig(): NamespaceConfig; } //# sourceMappingURL=namespace.d.ts.map