Merge commit 'd803bfe2b1fe7f5e219e50ac20d6801a0a58ac75' as 'vendor/ruvector'
This commit is contained in:
132
vendor/ruvector/npm/packages/rvf/dist/backend.d.ts
vendored
Normal file
132
vendor/ruvector/npm/packages/rvf/dist/backend.d.ts
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
import type { RvfOptions, RvfQueryOptions, RvfSearchResult, RvfIngestResult, RvfIngestEntry, RvfDeleteResult, RvfCompactionResult, RvfStatus, RvfFilterExpr, RvfKernelData, RvfEbpfData, RvfSegmentInfo, BackendType } from './types';
|
||||
/**
|
||||
* Abstract backend that wraps either the native (N-API) or WASM build of
|
||||
* rvf-runtime. The `RvfDatabase` class delegates all I/O to a backend
|
||||
* instance, keeping the public API identical regardless of runtime.
|
||||
*/
|
||||
export interface RvfBackend {
|
||||
/** Create a new store file at `path` with the given options. */
|
||||
create(path: string, options: RvfOptions): Promise<void>;
|
||||
/** Open an existing store at `path` for read-write access. */
|
||||
open(path: string): Promise<void>;
|
||||
/** Open an existing store at `path` for read-only access. */
|
||||
openReadonly(path: string): Promise<void>;
|
||||
/** Ingest a batch of vectors. */
|
||||
ingestBatch(entries: RvfIngestEntry[]): Promise<RvfIngestResult>;
|
||||
/** Query the k nearest neighbors. */
|
||||
query(vector: Float32Array, k: number, options?: RvfQueryOptions): Promise<RvfSearchResult[]>;
|
||||
/** Soft-delete vectors by ID. */
|
||||
delete(ids: string[]): Promise<RvfDeleteResult>;
|
||||
/** Soft-delete vectors matching a filter. */
|
||||
deleteByFilter(filter: RvfFilterExpr): Promise<RvfDeleteResult>;
|
||||
/** Run compaction to reclaim dead space. */
|
||||
compact(): Promise<RvfCompactionResult>;
|
||||
/** Get the current store status. */
|
||||
status(): Promise<RvfStatus>;
|
||||
/** Close the store, releasing locks. */
|
||||
close(): Promise<void>;
|
||||
fileId(): Promise<string>;
|
||||
parentId(): Promise<string>;
|
||||
lineageDepth(): Promise<number>;
|
||||
derive(childPath: string, options?: RvfOptions): Promise<RvfBackend>;
|
||||
embedKernel(arch: number, kernelType: number, flags: number, image: Uint8Array, apiPort: number, cmdline?: string): Promise<number>;
|
||||
extractKernel(): Promise<RvfKernelData | null>;
|
||||
embedEbpf(programType: number, attachType: number, maxDimension: number, bytecode: Uint8Array, btf?: Uint8Array): Promise<number>;
|
||||
extractEbpf(): Promise<RvfEbpfData | null>;
|
||||
segments(): Promise<RvfSegmentInfo[]>;
|
||||
dimension(): Promise<number>;
|
||||
}
|
||||
/**
|
||||
* Backend that delegates to the `@ruvector/rvf-node` native N-API addon.
|
||||
*
|
||||
* The native addon is loaded lazily on first use so that the SDK package can
|
||||
* be imported in environments where the native build is unavailable (e.g.
|
||||
* browsers) without throwing at import time.
|
||||
*/
|
||||
export declare class NodeBackend implements RvfBackend {
|
||||
private native;
|
||||
private handle;
|
||||
private idToLabel;
|
||||
private labelToId;
|
||||
private nextLabel;
|
||||
private storePath;
|
||||
private loadNative;
|
||||
private ensureHandle;
|
||||
create(path: string, options: RvfOptions): Promise<void>;
|
||||
open(path: string): Promise<void>;
|
||||
openReadonly(path: string): Promise<void>;
|
||||
ingestBatch(entries: RvfIngestEntry[]): Promise<RvfIngestResult>;
|
||||
query(vector: Float32Array, k: number, options?: RvfQueryOptions): Promise<RvfSearchResult[]>;
|
||||
delete(ids: string[]): Promise<RvfDeleteResult>;
|
||||
deleteByFilter(filter: RvfFilterExpr): Promise<RvfDeleteResult>;
|
||||
compact(): Promise<RvfCompactionResult>;
|
||||
status(): Promise<RvfStatus>;
|
||||
close(): Promise<void>;
|
||||
fileId(): Promise<string>;
|
||||
parentId(): Promise<string>;
|
||||
lineageDepth(): Promise<number>;
|
||||
derive(childPath: string, options?: RvfOptions): Promise<RvfBackend>;
|
||||
embedKernel(arch: number, kernelType: number, flags: number, image: Uint8Array, apiPort: number, cmdline?: string): Promise<number>;
|
||||
extractKernel(): Promise<RvfKernelData | null>;
|
||||
embedEbpf(programType: number, attachType: number, maxDimension: number, bytecode: Uint8Array, btf?: Uint8Array): Promise<number>;
|
||||
extractEbpf(): Promise<RvfEbpfData | null>;
|
||||
segments(): Promise<RvfSegmentInfo[]>;
|
||||
dimension(): Promise<number>;
|
||||
/**
|
||||
* Get or allocate a numeric label for a string ID.
|
||||
* If the ID was already seen, returns the existing label.
|
||||
*/
|
||||
private resolveLabel;
|
||||
/** Path to the sidecar mappings file. */
|
||||
private mappingsPath;
|
||||
/** Persist the string↔label mapping to a sidecar JSON file. */
|
||||
private saveMappings;
|
||||
/** Load the string↔label mapping from the sidecar JSON file if it exists. */
|
||||
private loadMappings;
|
||||
}
|
||||
/**
|
||||
* Backend that delegates to the `@ruvector/rvf-wasm` WASM build.
|
||||
*
|
||||
* The WASM microkernel exposes C-ABI store functions (`rvf_store_create`,
|
||||
* `rvf_store_query`, etc.) operating on integer handles. This backend wraps
|
||||
* them behind the same `RvfBackend` interface.
|
||||
*
|
||||
* Suitable for browser environments. The WASM module is loaded lazily.
|
||||
*/
|
||||
export declare class WasmBackend implements RvfBackend {
|
||||
private wasm;
|
||||
/** Integer store handle returned by `rvf_store_create` / `rvf_store_open`. */
|
||||
private handle;
|
||||
private dim;
|
||||
private loadWasm;
|
||||
private ensureHandle;
|
||||
private metricCode;
|
||||
create(_path: string, options: RvfOptions): Promise<void>;
|
||||
open(_path: string): Promise<void>;
|
||||
openReadonly(_path: string): Promise<void>;
|
||||
ingestBatch(entries: RvfIngestEntry[]): Promise<RvfIngestResult>;
|
||||
query(vector: Float32Array, k: number, _options?: RvfQueryOptions): Promise<RvfSearchResult[]>;
|
||||
delete(ids: string[]): Promise<RvfDeleteResult>;
|
||||
deleteByFilter(_filter: RvfFilterExpr): Promise<RvfDeleteResult>;
|
||||
compact(): Promise<RvfCompactionResult>;
|
||||
status(): Promise<RvfStatus>;
|
||||
close(): Promise<void>;
|
||||
fileId(): Promise<string>;
|
||||
parentId(): Promise<string>;
|
||||
lineageDepth(): Promise<number>;
|
||||
derive(_childPath: string, _options?: RvfOptions): Promise<RvfBackend>;
|
||||
embedKernel(): Promise<number>;
|
||||
extractKernel(): Promise<RvfKernelData | null>;
|
||||
embedEbpf(): Promise<number>;
|
||||
extractEbpf(): Promise<RvfEbpfData | null>;
|
||||
segments(): Promise<RvfSegmentInfo[]>;
|
||||
dimension(): Promise<number>;
|
||||
}
|
||||
/**
|
||||
* Resolve a `BackendType` to a concrete `RvfBackend` instance.
|
||||
*
|
||||
* - `'node'` Always returns a `NodeBackend`.
|
||||
* - `'wasm'` Always returns a `WasmBackend`.
|
||||
* - `'auto'` Tries `node` first, falls back to `wasm`.
|
||||
*/
|
||||
export declare function resolveBackend(type: BackendType): RvfBackend;
|
||||
731
vendor/ruvector/npm/packages/rvf/dist/backend.js
vendored
Normal file
731
vendor/ruvector/npm/packages/rvf/dist/backend.js
vendored
Normal file
@@ -0,0 +1,731 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.WasmBackend = exports.NodeBackend = void 0;
|
||||
exports.resolveBackend = resolveBackend;
|
||||
const errors_1 = require("./errors");
|
||||
// ---------------------------------------------------------------------------
|
||||
// NodeBackend — wraps @ruvector/rvf-node (N-API)
|
||||
// ---------------------------------------------------------------------------
|
||||
/**
|
||||
* Backend that delegates to the `@ruvector/rvf-node` native N-API addon.
|
||||
*
|
||||
* The native addon is loaded lazily on first use so that the SDK package can
|
||||
* be imported in environments where the native build is unavailable (e.g.
|
||||
* browsers) without throwing at import time.
|
||||
*/
|
||||
class NodeBackend {
|
||||
constructor() {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
this.native = null;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
this.handle = null;
|
||||
// String ID <-> Numeric Label mappings (N-API layer requires i64 labels)
|
||||
this.idToLabel = new Map();
|
||||
this.labelToId = new Map();
|
||||
this.nextLabel = 1; // RVF uses 1-based labels
|
||||
this.storePath = '';
|
||||
}
|
||||
async loadNative() {
|
||||
if (this.native)
|
||||
return;
|
||||
try {
|
||||
// Dynamic import so the SDK can be bundled for browsers without
|
||||
// pulling in the native addon at compile time.
|
||||
// The NAPI addon exports a `RvfDatabase` class with factory methods.
|
||||
const mod = await Promise.resolve().then(() => __importStar(require('@ruvector/rvf-node')));
|
||||
this.native = mod.RvfDatabase ?? mod.default?.RvfDatabase ?? mod;
|
||||
}
|
||||
catch {
|
||||
throw new errors_1.RvfError(errors_1.RvfErrorCode.BackendNotFound, 'Could not load @ruvector/rvf-node — is it installed?');
|
||||
}
|
||||
}
|
||||
ensureHandle() {
|
||||
if (!this.handle) {
|
||||
throw new errors_1.RvfError(errors_1.RvfErrorCode.StoreClosed);
|
||||
}
|
||||
}
|
||||
async create(path, options) {
|
||||
await this.loadNative();
|
||||
try {
|
||||
this.handle = await this.native.create(path, mapOptionsToNative(options));
|
||||
this.storePath = path;
|
||||
this.idToLabel.clear();
|
||||
this.labelToId.clear();
|
||||
this.nextLabel = 1;
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async open(path) {
|
||||
await this.loadNative();
|
||||
try {
|
||||
this.handle = await this.native.open(path);
|
||||
this.storePath = path;
|
||||
await this.loadMappings();
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async openReadonly(path) {
|
||||
await this.loadNative();
|
||||
try {
|
||||
this.handle = await this.native.openReadonly(path);
|
||||
this.storePath = path;
|
||||
await this.loadMappings();
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async ingestBatch(entries) {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
// NAPI signature: ingestBatch(vectors: Float32Array, ids: i64[], metadata?)
|
||||
// Flatten individual vectors into a single contiguous Float32Array.
|
||||
const n = entries.length;
|
||||
if (n === 0)
|
||||
return { accepted: 0, rejected: 0, epoch: 0 };
|
||||
const first = entries[0].vector;
|
||||
const dim = first instanceof Float32Array ? first.length : first.length;
|
||||
const flat = new Float32Array(n * dim);
|
||||
for (let i = 0; i < n; i++) {
|
||||
const v = entries[i].vector;
|
||||
const f32 = v instanceof Float32Array ? v : new Float32Array(v);
|
||||
flat.set(f32, i * dim);
|
||||
}
|
||||
// Map string IDs to numeric labels for the N-API layer.
|
||||
// The native Rust HNSW expects i64 labels — non-numeric strings cause
|
||||
// silent data loss (NaN → dropped). We maintain a bidirectional
|
||||
// string↔label mapping and persist it as a sidecar JSON file.
|
||||
const ids = entries.map((e) => this.resolveLabel(e.id));
|
||||
const result = this.handle.ingestBatch(flat, ids);
|
||||
// Persist mappings after every ingest so they survive crashes.
|
||||
await this.saveMappings();
|
||||
return {
|
||||
accepted: Number(result.accepted),
|
||||
rejected: Number(result.rejected),
|
||||
epoch: result.epoch,
|
||||
};
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async query(vector, k, options) {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
const nativeOpts = options ? mapQueryOptionsToNative(options) : undefined;
|
||||
const results = this.handle.query(vector, k, nativeOpts);
|
||||
// Map numeric labels back to original string IDs.
|
||||
return results.map((r) => ({
|
||||
id: this.labelToId.get(Number(r.id)) ?? String(r.id),
|
||||
distance: r.distance,
|
||||
}));
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async delete(ids) {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
// Resolve string IDs to numeric labels for the N-API layer.
|
||||
const numIds = ids
|
||||
.map((id) => this.idToLabel.get(id))
|
||||
.filter((label) => label !== undefined);
|
||||
if (numIds.length === 0) {
|
||||
return { deleted: 0, epoch: 0 };
|
||||
}
|
||||
const result = this.handle.delete(numIds);
|
||||
// Remove deleted entries from the mapping.
|
||||
for (const id of ids) {
|
||||
const label = this.idToLabel.get(id);
|
||||
if (label !== undefined) {
|
||||
this.idToLabel.delete(id);
|
||||
this.labelToId.delete(label);
|
||||
}
|
||||
}
|
||||
await this.saveMappings();
|
||||
return { deleted: Number(result.deleted), epoch: result.epoch };
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async deleteByFilter(filter) {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
// NAPI takes a JSON string for the filter expression.
|
||||
const result = this.handle.deleteByFilter(JSON.stringify(filter));
|
||||
return { deleted: Number(result.deleted), epoch: result.epoch };
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async compact() {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
const result = this.handle.compact();
|
||||
return {
|
||||
segmentsCompacted: result.segmentsCompacted ?? result.segments_compacted,
|
||||
bytesReclaimed: Number(result.bytesReclaimed ?? result.bytes_reclaimed),
|
||||
epoch: result.epoch,
|
||||
};
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async status() {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
const s = this.handle.status();
|
||||
return mapNativeStatus(s);
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async close() {
|
||||
if (!this.handle)
|
||||
return;
|
||||
try {
|
||||
await this.saveMappings();
|
||||
this.handle.close();
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
finally {
|
||||
this.handle = null;
|
||||
this.idToLabel.clear();
|
||||
this.labelToId.clear();
|
||||
this.nextLabel = 1;
|
||||
this.storePath = '';
|
||||
}
|
||||
}
|
||||
async fileId() {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
return this.handle.fileId();
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async parentId() {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
return this.handle.parentId();
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async lineageDepth() {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
return this.handle.lineageDepth();
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async derive(childPath, options) {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
const nativeOpts = options ? mapOptionsToNative(options) : undefined;
|
||||
const childHandle = this.handle.derive(childPath, nativeOpts);
|
||||
const child = new NodeBackend();
|
||||
child.native = this.native;
|
||||
child.handle = childHandle;
|
||||
child.storePath = childPath;
|
||||
// Copy parent mappings to child (COW semantics)
|
||||
child.idToLabel = new Map(this.idToLabel);
|
||||
child.labelToId = new Map(this.labelToId);
|
||||
child.nextLabel = this.nextLabel;
|
||||
await child.saveMappings();
|
||||
return child;
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async embedKernel(arch, kernelType, flags, image, apiPort, cmdline) {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
return this.handle.embedKernel(arch, kernelType, flags, Buffer.from(image), apiPort, cmdline);
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async extractKernel() {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
const result = this.handle.extractKernel();
|
||||
if (!result)
|
||||
return null;
|
||||
return {
|
||||
header: new Uint8Array(result.header),
|
||||
image: new Uint8Array(result.image),
|
||||
};
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async embedEbpf(programType, attachType, maxDimension, bytecode, btf) {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
return this.handle.embedEbpf(programType, attachType, maxDimension, Buffer.from(bytecode), btf ? Buffer.from(btf) : undefined);
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async extractEbpf() {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
const result = this.handle.extractEbpf();
|
||||
if (!result)
|
||||
return null;
|
||||
return {
|
||||
header: new Uint8Array(result.header),
|
||||
payload: new Uint8Array(result.payload),
|
||||
};
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async segments() {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
const segs = this.handle.segments();
|
||||
return segs.map((s) => ({
|
||||
id: s.id,
|
||||
offset: s.offset,
|
||||
payloadLength: s.payloadLength ?? s.payload_length,
|
||||
segType: s.segType ?? s.seg_type,
|
||||
}));
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async dimension() {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
return this.handle.dimension();
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
// ─── String ID ↔ Numeric Label mapping helpers ───
|
||||
/**
|
||||
* Get or allocate a numeric label for a string ID.
|
||||
* If the ID was already seen, returns the existing label.
|
||||
*/
|
||||
resolveLabel(id) {
|
||||
let label = this.idToLabel.get(id);
|
||||
if (label !== undefined)
|
||||
return label;
|
||||
label = this.nextLabel++;
|
||||
this.idToLabel.set(id, label);
|
||||
this.labelToId.set(label, id);
|
||||
return label;
|
||||
}
|
||||
/** Path to the sidecar mappings file. */
|
||||
mappingsPath() {
|
||||
return this.storePath ? this.storePath + '.idmap.json' : '';
|
||||
}
|
||||
/** Persist the string↔label mapping to a sidecar JSON file. */
|
||||
async saveMappings() {
|
||||
const mp = this.mappingsPath();
|
||||
if (!mp)
|
||||
return;
|
||||
try {
|
||||
const fs = await Promise.resolve().then(() => __importStar(require('fs')));
|
||||
const data = JSON.stringify({
|
||||
idToLabel: Object.fromEntries(this.idToLabel),
|
||||
labelToId: Object.fromEntries(Array.from(this.labelToId.entries()).map(([k, v]) => [String(k), v])),
|
||||
nextLabel: this.nextLabel,
|
||||
});
|
||||
fs.writeFileSync(mp, data, 'utf-8');
|
||||
}
|
||||
catch {
|
||||
// Non-fatal: mapping persistence is best-effort (e.g. read-only FS).
|
||||
}
|
||||
}
|
||||
/** Load the string↔label mapping from the sidecar JSON file if it exists. */
|
||||
async loadMappings() {
|
||||
const mp = this.mappingsPath();
|
||||
if (!mp)
|
||||
return;
|
||||
try {
|
||||
const fs = await Promise.resolve().then(() => __importStar(require('fs')));
|
||||
if (!fs.existsSync(mp))
|
||||
return;
|
||||
const raw = JSON.parse(fs.readFileSync(mp, 'utf-8'));
|
||||
this.idToLabel = new Map(Object.entries(raw.idToLabel ?? {}).map(([k, v]) => [k, Number(v)]));
|
||||
this.labelToId = new Map(Object.entries(raw.labelToId ?? {}).map(([k, v]) => [Number(k), v]));
|
||||
this.nextLabel = raw.nextLabel ?? this.idToLabel.size + 1;
|
||||
}
|
||||
catch {
|
||||
// Non-fatal: start with empty mappings.
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.NodeBackend = NodeBackend;
|
||||
// ---------------------------------------------------------------------------
|
||||
// WasmBackend — wraps @ruvector/rvf-wasm
|
||||
// ---------------------------------------------------------------------------
|
||||
/**
|
||||
* Backend that delegates to the `@ruvector/rvf-wasm` WASM build.
|
||||
*
|
||||
* The WASM microkernel exposes C-ABI store functions (`rvf_store_create`,
|
||||
* `rvf_store_query`, etc.) operating on integer handles. This backend wraps
|
||||
* them behind the same `RvfBackend` interface.
|
||||
*
|
||||
* Suitable for browser environments. The WASM module is loaded lazily.
|
||||
*/
|
||||
class WasmBackend {
|
||||
constructor() {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
this.wasm = null;
|
||||
/** Integer store handle returned by `rvf_store_create` / `rvf_store_open`. */
|
||||
this.handle = 0;
|
||||
this.dim = 0;
|
||||
}
|
||||
async loadWasm() {
|
||||
if (this.wasm)
|
||||
return;
|
||||
try {
|
||||
const mod = await Promise.resolve().then(() => __importStar(require('@ruvector/rvf-wasm')));
|
||||
// wasm-pack default export is the init function
|
||||
if (typeof mod.default === 'function') {
|
||||
this.wasm = await mod.default();
|
||||
}
|
||||
else {
|
||||
this.wasm = mod;
|
||||
}
|
||||
}
|
||||
catch {
|
||||
throw new errors_1.RvfError(errors_1.RvfErrorCode.BackendNotFound, 'Could not load @ruvector/rvf-wasm — is it installed?');
|
||||
}
|
||||
}
|
||||
ensureHandle() {
|
||||
if (!this.handle) {
|
||||
throw new errors_1.RvfError(errors_1.RvfErrorCode.StoreClosed);
|
||||
}
|
||||
}
|
||||
metricCode(metric) {
|
||||
switch (metric) {
|
||||
case 'Cosine': return 2;
|
||||
case 'InnerProduct': return 1;
|
||||
default: return 0; // L2
|
||||
}
|
||||
}
|
||||
async create(_path, options) {
|
||||
await this.loadWasm();
|
||||
try {
|
||||
const nativeOpts = mapOptionsToNative(options);
|
||||
const dim = nativeOpts.dimension;
|
||||
const metric = this.metricCode(nativeOpts.metric);
|
||||
const h = this.wasm.rvf_store_create(dim, metric);
|
||||
if (h <= 0)
|
||||
throw new Error('rvf_store_create returned ' + h);
|
||||
this.handle = h;
|
||||
this.dim = dim;
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async open(_path) {
|
||||
throw new errors_1.RvfError(errors_1.RvfErrorCode.BackendNotFound, 'WASM backend does not support file-based open (in-memory only)');
|
||||
}
|
||||
async openReadonly(_path) {
|
||||
throw new errors_1.RvfError(errors_1.RvfErrorCode.BackendNotFound, 'WASM backend does not support file-based openReadonly (in-memory only)');
|
||||
}
|
||||
async ingestBatch(entries) {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
const n = entries.length;
|
||||
if (n === 0)
|
||||
return { accepted: 0, rejected: 0, epoch: 0 };
|
||||
const dim = this.dim || (entries[0].vector instanceof Float32Array
|
||||
? entries[0].vector.length : entries[0].vector.length);
|
||||
const flat = new Float32Array(n * dim);
|
||||
const ids = new BigUint64Array(n);
|
||||
for (let i = 0; i < n; i++) {
|
||||
const v = entries[i].vector;
|
||||
const f32 = v instanceof Float32Array ? v : new Float32Array(v);
|
||||
flat.set(f32, i * dim);
|
||||
ids[i] = BigInt(entries[i].id);
|
||||
}
|
||||
// Allocate in WASM memory and call
|
||||
const vecsPtr = this.wasm.rvf_alloc(flat.byteLength);
|
||||
const idsPtr = this.wasm.rvf_alloc(ids.byteLength);
|
||||
new Float32Array(this.wasm.memory.buffer, vecsPtr, flat.length).set(flat);
|
||||
new BigUint64Array(this.wasm.memory.buffer, idsPtr, ids.length).set(ids);
|
||||
const accepted = this.wasm.rvf_store_ingest(this.handle, vecsPtr, idsPtr, n);
|
||||
this.wasm.rvf_free(vecsPtr, flat.byteLength);
|
||||
this.wasm.rvf_free(idsPtr, ids.byteLength);
|
||||
return { accepted: accepted > 0 ? accepted : 0, rejected: accepted < 0 ? n : 0, epoch: 0 };
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async query(vector, k, _options) {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
const queryPtr = this.wasm.rvf_alloc(vector.byteLength);
|
||||
new Float32Array(this.wasm.memory.buffer, queryPtr, vector.length).set(vector);
|
||||
// Each result = 8 bytes id + 4 bytes dist = 12 bytes
|
||||
const outSize = k * 12;
|
||||
const outPtr = this.wasm.rvf_alloc(outSize);
|
||||
const count = this.wasm.rvf_store_query(this.handle, queryPtr, k, 0, outPtr);
|
||||
const results = [];
|
||||
const view = new DataView(this.wasm.memory.buffer);
|
||||
for (let i = 0; i < count; i++) {
|
||||
const off = outPtr + i * 12;
|
||||
const id = view.getBigUint64(off, true);
|
||||
const dist = view.getFloat32(off + 8, true);
|
||||
results.push({ id: String(id), distance: dist });
|
||||
}
|
||||
this.wasm.rvf_free(queryPtr, vector.byteLength);
|
||||
this.wasm.rvf_free(outPtr, outSize);
|
||||
return results;
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async delete(ids) {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
const arr = new BigUint64Array(ids.map((id) => BigInt(id)));
|
||||
const ptr = this.wasm.rvf_alloc(arr.byteLength);
|
||||
new BigUint64Array(this.wasm.memory.buffer, ptr, arr.length).set(arr);
|
||||
const deleted = this.wasm.rvf_store_delete(this.handle, ptr, ids.length);
|
||||
this.wasm.rvf_free(ptr, arr.byteLength);
|
||||
return { deleted: deleted > 0 ? deleted : 0, epoch: 0 };
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async deleteByFilter(_filter) {
|
||||
throw new errors_1.RvfError(errors_1.RvfErrorCode.BackendNotFound, 'deleteByFilter not supported in WASM backend');
|
||||
}
|
||||
async compact() {
|
||||
return { segmentsCompacted: 0, bytesReclaimed: 0, epoch: 0 };
|
||||
}
|
||||
async status() {
|
||||
this.ensureHandle();
|
||||
try {
|
||||
const outPtr = this.wasm.rvf_alloc(20);
|
||||
this.wasm.rvf_store_status(this.handle, outPtr);
|
||||
const view = new DataView(this.wasm.memory.buffer);
|
||||
const totalVectors = view.getUint32(outPtr, true);
|
||||
const dim = view.getUint32(outPtr + 4, true);
|
||||
this.wasm.rvf_free(outPtr, 20);
|
||||
return {
|
||||
totalVectors,
|
||||
totalSegments: 1,
|
||||
fileSizeBytes: 0,
|
||||
epoch: 0,
|
||||
profileId: 0,
|
||||
compactionState: 'idle',
|
||||
deadSpaceRatio: 0,
|
||||
readOnly: false,
|
||||
};
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
}
|
||||
async close() {
|
||||
if (!this.handle)
|
||||
return;
|
||||
try {
|
||||
this.wasm.rvf_store_close(this.handle);
|
||||
}
|
||||
catch (err) {
|
||||
throw errors_1.RvfError.fromNative(err);
|
||||
}
|
||||
finally {
|
||||
this.handle = 0;
|
||||
}
|
||||
}
|
||||
async fileId() {
|
||||
throw new errors_1.RvfError(errors_1.RvfErrorCode.BackendNotFound, 'fileId not supported in WASM backend');
|
||||
}
|
||||
async parentId() {
|
||||
throw new errors_1.RvfError(errors_1.RvfErrorCode.BackendNotFound, 'parentId not supported in WASM backend');
|
||||
}
|
||||
async lineageDepth() {
|
||||
throw new errors_1.RvfError(errors_1.RvfErrorCode.BackendNotFound, 'lineageDepth not supported in WASM backend');
|
||||
}
|
||||
async derive(_childPath, _options) {
|
||||
throw new errors_1.RvfError(errors_1.RvfErrorCode.BackendNotFound, 'derive not supported in WASM backend');
|
||||
}
|
||||
async embedKernel() {
|
||||
throw new errors_1.RvfError(errors_1.RvfErrorCode.BackendNotFound, 'embedKernel not supported in WASM backend');
|
||||
}
|
||||
async extractKernel() {
|
||||
throw new errors_1.RvfError(errors_1.RvfErrorCode.BackendNotFound, 'extractKernel not supported in WASM backend');
|
||||
}
|
||||
async embedEbpf() {
|
||||
throw new errors_1.RvfError(errors_1.RvfErrorCode.BackendNotFound, 'embedEbpf not supported in WASM backend');
|
||||
}
|
||||
async extractEbpf() {
|
||||
throw new errors_1.RvfError(errors_1.RvfErrorCode.BackendNotFound, 'extractEbpf not supported in WASM backend');
|
||||
}
|
||||
async segments() {
|
||||
throw new errors_1.RvfError(errors_1.RvfErrorCode.BackendNotFound, 'segments not supported in WASM backend');
|
||||
}
|
||||
async dimension() {
|
||||
this.ensureHandle();
|
||||
const d = this.wasm.rvf_store_dimension(this.handle);
|
||||
if (d < 0)
|
||||
throw new errors_1.RvfError(errors_1.RvfErrorCode.StoreClosed);
|
||||
return d;
|
||||
}
|
||||
}
|
||||
exports.WasmBackend = WasmBackend;
|
||||
// ---------------------------------------------------------------------------
|
||||
// Backend resolution
|
||||
// ---------------------------------------------------------------------------
|
||||
/**
|
||||
* Resolve a `BackendType` to a concrete `RvfBackend` instance.
|
||||
*
|
||||
* - `'node'` Always returns a `NodeBackend`.
|
||||
* - `'wasm'` Always returns a `WasmBackend`.
|
||||
* - `'auto'` Tries `node` first, falls back to `wasm`.
|
||||
*/
|
||||
function resolveBackend(type) {
|
||||
switch (type) {
|
||||
case 'node':
|
||||
return new NodeBackend();
|
||||
case 'wasm':
|
||||
return new WasmBackend();
|
||||
case 'auto': {
|
||||
// In Node.js environments, prefer native; in browsers, prefer WASM.
|
||||
const isNode = typeof process !== 'undefined' &&
|
||||
typeof process.versions !== 'undefined' &&
|
||||
typeof process.versions.node === 'string';
|
||||
return isNode ? new NodeBackend() : new WasmBackend();
|
||||
}
|
||||
}
|
||||
}
|
||||
// ---------------------------------------------------------------------------
|
||||
// Mapping helpers (TS options -> native/wasm shapes)
|
||||
// ---------------------------------------------------------------------------
|
||||
function mapMetricToNative(metric) {
|
||||
switch (metric) {
|
||||
case 'cosine':
|
||||
return 'Cosine';
|
||||
case 'dotproduct':
|
||||
return 'InnerProduct';
|
||||
case 'l2':
|
||||
default:
|
||||
return 'L2';
|
||||
}
|
||||
}
|
||||
function mapCompressionToNative(compression) {
|
||||
switch (compression) {
|
||||
case 'scalar':
|
||||
return 'Scalar';
|
||||
case 'product':
|
||||
return 'Product';
|
||||
case 'none':
|
||||
default:
|
||||
return 'None';
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function mapOptionsToNative(options) {
|
||||
return {
|
||||
dimension: options.dimensions,
|
||||
metric: mapMetricToNative(options.metric),
|
||||
profile: options.profile ?? 0,
|
||||
compression: mapCompressionToNative(options.compression),
|
||||
signing: options.signing ?? false,
|
||||
m: options.m ?? 16,
|
||||
ef_construction: options.efConstruction ?? 200,
|
||||
};
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function mapQueryOptionsToNative(options) {
|
||||
return {
|
||||
ef_search: options.efSearch ?? 100,
|
||||
// NAPI accepts the filter as a JSON string, not an object.
|
||||
filter: options.filter ? JSON.stringify(options.filter) : undefined,
|
||||
timeout_ms: options.timeoutMs ?? 0,
|
||||
};
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function mapNativeStatus(s) {
|
||||
return {
|
||||
totalVectors: s.total_vectors ?? s.totalVectors ?? 0,
|
||||
totalSegments: s.total_segments ?? s.totalSegments ?? 0,
|
||||
fileSizeBytes: s.file_size ?? s.fileSizeBytes ?? 0,
|
||||
epoch: s.current_epoch ?? s.epoch ?? 0,
|
||||
profileId: s.profile_id ?? s.profileId ?? 0,
|
||||
compactionState: mapCompactionState(s.compaction_state ?? s.compactionState),
|
||||
deadSpaceRatio: s.dead_space_ratio ?? s.deadSpaceRatio ?? 0,
|
||||
readOnly: s.read_only ?? s.readOnly ?? false,
|
||||
};
|
||||
}
|
||||
function mapCompactionState(state) {
|
||||
if (typeof state === 'string') {
|
||||
const lower = state.toLowerCase();
|
||||
if (lower === 'running')
|
||||
return 'running';
|
||||
if (lower === 'emergency')
|
||||
return 'emergency';
|
||||
}
|
||||
return 'idle';
|
||||
}
|
||||
//# sourceMappingURL=backend.js.map
|
||||
1
vendor/ruvector/npm/packages/rvf/dist/backend.js.map
vendored
Normal file
1
vendor/ruvector/npm/packages/rvf/dist/backend.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
118
vendor/ruvector/npm/packages/rvf/dist/database.d.ts
vendored
Normal file
118
vendor/ruvector/npm/packages/rvf/dist/database.d.ts
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
import type { RvfOptions, RvfQueryOptions, RvfSearchResult, RvfIngestResult, RvfIngestEntry, RvfDeleteResult, RvfCompactionResult, RvfStatus, RvfFilterExpr, RvfKernelData, RvfEbpfData, RvfSegmentInfo, BackendType } from './types';
|
||||
import type { RvfBackend } from './backend';
|
||||
/**
|
||||
* Main user-facing RVF database class.
|
||||
*
|
||||
* Wraps a backend implementation (`NodeBackend` or `WasmBackend`) and exposes
|
||||
* an ergonomic async API that mirrors the Rust `RvfStore` surface.
|
||||
*
|
||||
* Use the static factory methods (`create`, `open`, `openReadonly`) to obtain
|
||||
* an instance. Do not construct directly.
|
||||
*/
|
||||
export declare class RvfDatabase {
|
||||
private backend;
|
||||
private closed;
|
||||
private constructor();
|
||||
/**
|
||||
* Create a new RVF store at `path`.
|
||||
*
|
||||
* @param path File path for the new store.
|
||||
* @param options Store creation options (dimensions is required).
|
||||
* @param backend Backend to use. Default: `'auto'`.
|
||||
*/
|
||||
static create(path: string, options: RvfOptions, backend?: BackendType): Promise<RvfDatabase>;
|
||||
/**
|
||||
* Open an existing RVF store for read-write access.
|
||||
*
|
||||
* @param path File path to an existing `.rvf` file.
|
||||
* @param backend Backend to use. Default: `'auto'`.
|
||||
*/
|
||||
static open(path: string, backend?: BackendType): Promise<RvfDatabase>;
|
||||
/**
|
||||
* Open an existing RVF store for read-only access (no lock required).
|
||||
*
|
||||
* @param path File path to an existing `.rvf` file.
|
||||
* @param backend Backend to use. Default: `'auto'`.
|
||||
*/
|
||||
static openReadonly(path: string, backend?: BackendType): Promise<RvfDatabase>;
|
||||
/**
|
||||
* Create an RvfDatabase from an already-initialized backend.
|
||||
*
|
||||
* Used internally (e.g. by `derive()`) to wrap a child backend that was
|
||||
* created by the native layer without going through the normal open/create
|
||||
* flow.
|
||||
*/
|
||||
static fromBackend(backend: RvfBackend): RvfDatabase;
|
||||
/**
|
||||
* Ingest a batch of vectors into the store.
|
||||
*
|
||||
* @param entries Array of `{ id, vector, metadata? }` entries.
|
||||
* @returns Counts of accepted/rejected vectors and the new epoch.
|
||||
*/
|
||||
ingestBatch(entries: RvfIngestEntry[]): Promise<RvfIngestResult>;
|
||||
/**
|
||||
* Soft-delete vectors by their IDs.
|
||||
*
|
||||
* @param ids Vector IDs to delete.
|
||||
*/
|
||||
delete(ids: string[]): Promise<RvfDeleteResult>;
|
||||
/**
|
||||
* Soft-delete all vectors matching a filter expression.
|
||||
*
|
||||
* @param filter The filter to match against vector metadata.
|
||||
*/
|
||||
deleteByFilter(filter: RvfFilterExpr): Promise<RvfDeleteResult>;
|
||||
/**
|
||||
* Query for the `k` nearest neighbors of a given vector.
|
||||
*
|
||||
* @param vector The query embedding.
|
||||
* @param k Number of results to return.
|
||||
* @param options Optional query parameters (efSearch, filter, timeout).
|
||||
* @returns Sorted search results (closest first).
|
||||
*/
|
||||
query(vector: Float32Array | number[], k: number, options?: RvfQueryOptions): Promise<RvfSearchResult[]>;
|
||||
/**
|
||||
* Run compaction to reclaim dead space from soft-deleted vectors.
|
||||
*/
|
||||
compact(): Promise<RvfCompactionResult>;
|
||||
/**
|
||||
* Get the current store status (vector count, file size, epoch, etc.).
|
||||
*/
|
||||
status(): Promise<RvfStatus>;
|
||||
/** Get this file's unique identifier as a hex string. */
|
||||
fileId(): Promise<string>;
|
||||
/** Get the parent file's identifier as a hex string (all zeros if root). */
|
||||
parentId(): Promise<string>;
|
||||
/** Get the lineage depth (0 for root files). */
|
||||
lineageDepth(): Promise<number>;
|
||||
/**
|
||||
* Derive a child store from this parent.
|
||||
*
|
||||
* Creates a new RVF file at `childPath` that records this store as its
|
||||
* parent for provenance tracking. Returns a new `RvfDatabase` wrapping
|
||||
* the child store.
|
||||
*/
|
||||
derive(childPath: string, options?: RvfOptions): Promise<RvfDatabase>;
|
||||
/** Embed a kernel image. Returns the segment ID. */
|
||||
embedKernel(arch: number, kernelType: number, flags: number, image: Uint8Array, apiPort: number, cmdline?: string): Promise<number>;
|
||||
/** Extract the kernel image. Returns null if not present. */
|
||||
extractKernel(): Promise<RvfKernelData | null>;
|
||||
/** Embed an eBPF program. Returns the segment ID. */
|
||||
embedEbpf(programType: number, attachType: number, maxDimension: number, bytecode: Uint8Array, btf?: Uint8Array): Promise<number>;
|
||||
/** Extract the eBPF program. Returns null if not present. */
|
||||
extractEbpf(): Promise<RvfEbpfData | null>;
|
||||
/** Get the list of segments in the store. */
|
||||
segments(): Promise<RvfSegmentInfo[]>;
|
||||
/** Get the vector dimensionality. */
|
||||
dimension(): Promise<number>;
|
||||
/**
|
||||
* Close the store, releasing the writer lock and flushing pending data.
|
||||
*
|
||||
* After calling `close()`, all other methods will throw `RvfError` with
|
||||
* code `StoreClosed`.
|
||||
*/
|
||||
close(): Promise<void>;
|
||||
/** True if the store has been closed. */
|
||||
get isClosed(): boolean;
|
||||
private ensureOpen;
|
||||
}
|
||||
226
vendor/ruvector/npm/packages/rvf/dist/database.js
vendored
Normal file
226
vendor/ruvector/npm/packages/rvf/dist/database.js
vendored
Normal file
@@ -0,0 +1,226 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RvfDatabase = void 0;
|
||||
const backend_1 = require("./backend");
|
||||
const errors_1 = require("./errors");
|
||||
/**
|
||||
* Main user-facing RVF database class.
|
||||
*
|
||||
* Wraps a backend implementation (`NodeBackend` or `WasmBackend`) and exposes
|
||||
* an ergonomic async API that mirrors the Rust `RvfStore` surface.
|
||||
*
|
||||
* Use the static factory methods (`create`, `open`, `openReadonly`) to obtain
|
||||
* an instance. Do not construct directly.
|
||||
*/
|
||||
class RvfDatabase {
|
||||
constructor(backend) {
|
||||
this.closed = false;
|
||||
this.backend = backend;
|
||||
}
|
||||
// -----------------------------------------------------------------------
|
||||
// Factory methods
|
||||
// -----------------------------------------------------------------------
|
||||
/**
|
||||
* Create a new RVF store at `path`.
|
||||
*
|
||||
* @param path File path for the new store.
|
||||
* @param options Store creation options (dimensions is required).
|
||||
* @param backend Backend to use. Default: `'auto'`.
|
||||
*/
|
||||
static async create(path, options, backend = 'auto') {
|
||||
const impl = (0, backend_1.resolveBackend)(backend);
|
||||
await impl.create(path, options);
|
||||
return new RvfDatabase(impl);
|
||||
}
|
||||
/**
|
||||
* Open an existing RVF store for read-write access.
|
||||
*
|
||||
* @param path File path to an existing `.rvf` file.
|
||||
* @param backend Backend to use. Default: `'auto'`.
|
||||
*/
|
||||
static async open(path, backend = 'auto') {
|
||||
const impl = (0, backend_1.resolveBackend)(backend);
|
||||
await impl.open(path);
|
||||
return new RvfDatabase(impl);
|
||||
}
|
||||
/**
|
||||
* Open an existing RVF store for read-only access (no lock required).
|
||||
*
|
||||
* @param path File path to an existing `.rvf` file.
|
||||
* @param backend Backend to use. Default: `'auto'`.
|
||||
*/
|
||||
static async openReadonly(path, backend = 'auto') {
|
||||
const impl = (0, backend_1.resolveBackend)(backend);
|
||||
await impl.openReadonly(path);
|
||||
return new RvfDatabase(impl);
|
||||
}
|
||||
/**
|
||||
* Create an RvfDatabase from an already-initialized backend.
|
||||
*
|
||||
* Used internally (e.g. by `derive()`) to wrap a child backend that was
|
||||
* created by the native layer without going through the normal open/create
|
||||
* flow.
|
||||
*/
|
||||
static fromBackend(backend) {
|
||||
return new RvfDatabase(backend);
|
||||
}
|
||||
// -----------------------------------------------------------------------
|
||||
// Write operations
|
||||
// -----------------------------------------------------------------------
|
||||
/**
|
||||
* Ingest a batch of vectors into the store.
|
||||
*
|
||||
* @param entries Array of `{ id, vector, metadata? }` entries.
|
||||
* @returns Counts of accepted/rejected vectors and the new epoch.
|
||||
*/
|
||||
async ingestBatch(entries) {
|
||||
this.ensureOpen();
|
||||
return this.backend.ingestBatch(entries);
|
||||
}
|
||||
/**
|
||||
* Soft-delete vectors by their IDs.
|
||||
*
|
||||
* @param ids Vector IDs to delete.
|
||||
*/
|
||||
async delete(ids) {
|
||||
this.ensureOpen();
|
||||
return this.backend.delete(ids);
|
||||
}
|
||||
/**
|
||||
* Soft-delete all vectors matching a filter expression.
|
||||
*
|
||||
* @param filter The filter to match against vector metadata.
|
||||
*/
|
||||
async deleteByFilter(filter) {
|
||||
this.ensureOpen();
|
||||
return this.backend.deleteByFilter(filter);
|
||||
}
|
||||
// -----------------------------------------------------------------------
|
||||
// Read operations
|
||||
// -----------------------------------------------------------------------
|
||||
/**
|
||||
* Query for the `k` nearest neighbors of a given vector.
|
||||
*
|
||||
* @param vector The query embedding.
|
||||
* @param k Number of results to return.
|
||||
* @param options Optional query parameters (efSearch, filter, timeout).
|
||||
* @returns Sorted search results (closest first).
|
||||
*/
|
||||
async query(vector, k, options) {
|
||||
this.ensureOpen();
|
||||
const f32 = vector instanceof Float32Array ? vector : new Float32Array(vector);
|
||||
return this.backend.query(f32, k, options);
|
||||
}
|
||||
// -----------------------------------------------------------------------
|
||||
// Maintenance
|
||||
// -----------------------------------------------------------------------
|
||||
/**
|
||||
* Run compaction to reclaim dead space from soft-deleted vectors.
|
||||
*/
|
||||
async compact() {
|
||||
this.ensureOpen();
|
||||
return this.backend.compact();
|
||||
}
|
||||
/**
|
||||
* Get the current store status (vector count, file size, epoch, etc.).
|
||||
*/
|
||||
async status() {
|
||||
this.ensureOpen();
|
||||
return this.backend.status();
|
||||
}
|
||||
// -----------------------------------------------------------------------
|
||||
// Lineage
|
||||
// -----------------------------------------------------------------------
|
||||
/** Get this file's unique identifier as a hex string. */
|
||||
async fileId() {
|
||||
this.ensureOpen();
|
||||
return this.backend.fileId();
|
||||
}
|
||||
/** Get the parent file's identifier as a hex string (all zeros if root). */
|
||||
async parentId() {
|
||||
this.ensureOpen();
|
||||
return this.backend.parentId();
|
||||
}
|
||||
/** Get the lineage depth (0 for root files). */
|
||||
async lineageDepth() {
|
||||
this.ensureOpen();
|
||||
return this.backend.lineageDepth();
|
||||
}
|
||||
/**
|
||||
* Derive a child store from this parent.
|
||||
*
|
||||
* Creates a new RVF file at `childPath` that records this store as its
|
||||
* parent for provenance tracking. Returns a new `RvfDatabase` wrapping
|
||||
* the child store.
|
||||
*/
|
||||
async derive(childPath, options) {
|
||||
this.ensureOpen();
|
||||
const childBackend = await this.backend.derive(childPath, options);
|
||||
return RvfDatabase.fromBackend(childBackend);
|
||||
}
|
||||
// -----------------------------------------------------------------------
|
||||
// Kernel / eBPF
|
||||
// -----------------------------------------------------------------------
|
||||
/** Embed a kernel image. Returns the segment ID. */
|
||||
async embedKernel(arch, kernelType, flags, image, apiPort, cmdline) {
|
||||
this.ensureOpen();
|
||||
return this.backend.embedKernel(arch, kernelType, flags, image, apiPort, cmdline);
|
||||
}
|
||||
/** Extract the kernel image. Returns null if not present. */
|
||||
async extractKernel() {
|
||||
this.ensureOpen();
|
||||
return this.backend.extractKernel();
|
||||
}
|
||||
/** Embed an eBPF program. Returns the segment ID. */
|
||||
async embedEbpf(programType, attachType, maxDimension, bytecode, btf) {
|
||||
this.ensureOpen();
|
||||
return this.backend.embedEbpf(programType, attachType, maxDimension, bytecode, btf);
|
||||
}
|
||||
/** Extract the eBPF program. Returns null if not present. */
|
||||
async extractEbpf() {
|
||||
this.ensureOpen();
|
||||
return this.backend.extractEbpf();
|
||||
}
|
||||
// -----------------------------------------------------------------------
|
||||
// Inspection
|
||||
// -----------------------------------------------------------------------
|
||||
/** Get the list of segments in the store. */
|
||||
async segments() {
|
||||
this.ensureOpen();
|
||||
return this.backend.segments();
|
||||
}
|
||||
/** Get the vector dimensionality. */
|
||||
async dimension() {
|
||||
this.ensureOpen();
|
||||
return this.backend.dimension();
|
||||
}
|
||||
// -----------------------------------------------------------------------
|
||||
// Lifecycle
|
||||
// -----------------------------------------------------------------------
|
||||
/**
|
||||
* Close the store, releasing the writer lock and flushing pending data.
|
||||
*
|
||||
* After calling `close()`, all other methods will throw `RvfError` with
|
||||
* code `StoreClosed`.
|
||||
*/
|
||||
async close() {
|
||||
if (this.closed)
|
||||
return;
|
||||
this.closed = true;
|
||||
await this.backend.close();
|
||||
}
|
||||
/** True if the store has been closed. */
|
||||
get isClosed() {
|
||||
return this.closed;
|
||||
}
|
||||
// -----------------------------------------------------------------------
|
||||
// Internal
|
||||
// -----------------------------------------------------------------------
|
||||
ensureOpen() {
|
||||
if (this.closed) {
|
||||
throw new errors_1.RvfError(errors_1.RvfErrorCode.StoreClosed);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.RvfDatabase = RvfDatabase;
|
||||
//# sourceMappingURL=database.js.map
|
||||
1
vendor/ruvector/npm/packages/rvf/dist/database.js.map
vendored
Normal file
1
vendor/ruvector/npm/packages/rvf/dist/database.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"database.js","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":";;;AAgBA,uCAA2C;AAC3C,qCAAkD;AAElD;;;;;;;;GAQG;AACH,MAAa,WAAW;IAItB,YAAoB,OAAmB;QAF/B,WAAM,GAAG,KAAK,CAAC;QAGrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,0EAA0E;IAC1E,kBAAkB;IAClB,0EAA0E;IAE1E;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,IAAY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CAAC;IACpC,CAAC;IAED,0EAA0E;IAC1E,aAAa;IACb,0EAA0E;IAE1E,6CAA6C;IAC7C,KAAK,CAAC,QAAQ;QACZ,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;IAED,qCAAqC;IACrC,KAAK,CAAC,SAAS;QACb,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;IAClC,CAAC;IAED,0EAA0E;IAC1E,YAAY;IACZ,0EAA0E;IAE1E;;;;;OAKG;IACH,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED,yCAAyC;IACzC,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,0EAA0E;IAC1E,WAAW;IACX,0EAA0E;IAElE,UAAU;QAChB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,IAAI,iBAAQ,CAAC,qBAAY,CAAC,WAAW,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;CACF;AAtQD,kCAsQC"}
|
||||
62
vendor/ruvector/npm/packages/rvf/dist/errors.d.ts
vendored
Normal file
62
vendor/ruvector/npm/packages/rvf/dist/errors.d.ts
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Error codes mirroring the Rust `ErrorCode` enum (rvf-types).
|
||||
*
|
||||
* The high byte is the category, the low byte is the specific error.
|
||||
*/
|
||||
export declare enum RvfErrorCode {
|
||||
Ok = 0,
|
||||
OkPartial = 1,
|
||||
InvalidMagic = 256,
|
||||
InvalidVersion = 257,
|
||||
InvalidChecksum = 258,
|
||||
InvalidSignature = 259,
|
||||
TruncatedSegment = 260,
|
||||
InvalidManifest = 261,
|
||||
ManifestNotFound = 262,
|
||||
UnknownSegmentType = 263,
|
||||
AlignmentError = 264,
|
||||
DimensionMismatch = 512,
|
||||
EmptyIndex = 513,
|
||||
MetricUnsupported = 514,
|
||||
FilterParseError = 515,
|
||||
KTooLarge = 516,
|
||||
Timeout = 517,
|
||||
LockHeld = 768,
|
||||
LockStale = 769,
|
||||
DiskFull = 770,
|
||||
FsyncFailed = 771,
|
||||
SegmentTooLarge = 772,
|
||||
ReadOnly = 773,
|
||||
TileTrap = 1024,
|
||||
TileOom = 1025,
|
||||
TileTimeout = 1026,
|
||||
TileInvalidMsg = 1027,
|
||||
TileUnsupportedOp = 1028,
|
||||
KeyNotFound = 1280,
|
||||
KeyExpired = 1281,
|
||||
DecryptFailed = 1282,
|
||||
AlgoUnsupported = 1283,
|
||||
BackendNotFound = 65280,
|
||||
BackendInitFailed = 65281,
|
||||
StoreClosed = 65282
|
||||
}
|
||||
/**
|
||||
* Custom error class for all RVF operations.
|
||||
*
|
||||
* Carries a typed `code` field for programmatic matching and a
|
||||
* human-readable `message`.
|
||||
*/
|
||||
export declare class RvfError extends Error {
|
||||
/** The RVF error code. */
|
||||
readonly code: RvfErrorCode;
|
||||
/** Error category (high byte of the code). */
|
||||
get category(): number;
|
||||
/** True when the category indicates a format-level (fatal) error. */
|
||||
get isFormatError(): boolean;
|
||||
constructor(code: RvfErrorCode, detail?: string);
|
||||
/**
|
||||
* Create an RvfError from a native binding error.
|
||||
* Attempts to extract an error code from the message or object.
|
||||
*/
|
||||
static fromNative(err: unknown): RvfError;
|
||||
}
|
||||
135
vendor/ruvector/npm/packages/rvf/dist/errors.js
vendored
Normal file
135
vendor/ruvector/npm/packages/rvf/dist/errors.js
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RvfError = exports.RvfErrorCode = void 0;
|
||||
/**
|
||||
* Error codes mirroring the Rust `ErrorCode` enum (rvf-types).
|
||||
*
|
||||
* The high byte is the category, the low byte is the specific error.
|
||||
*/
|
||||
var RvfErrorCode;
|
||||
(function (RvfErrorCode) {
|
||||
// Category 0x00: Success
|
||||
RvfErrorCode[RvfErrorCode["Ok"] = 0] = "Ok";
|
||||
RvfErrorCode[RvfErrorCode["OkPartial"] = 1] = "OkPartial";
|
||||
// Category 0x01: Format Errors
|
||||
RvfErrorCode[RvfErrorCode["InvalidMagic"] = 256] = "InvalidMagic";
|
||||
RvfErrorCode[RvfErrorCode["InvalidVersion"] = 257] = "InvalidVersion";
|
||||
RvfErrorCode[RvfErrorCode["InvalidChecksum"] = 258] = "InvalidChecksum";
|
||||
RvfErrorCode[RvfErrorCode["InvalidSignature"] = 259] = "InvalidSignature";
|
||||
RvfErrorCode[RvfErrorCode["TruncatedSegment"] = 260] = "TruncatedSegment";
|
||||
RvfErrorCode[RvfErrorCode["InvalidManifest"] = 261] = "InvalidManifest";
|
||||
RvfErrorCode[RvfErrorCode["ManifestNotFound"] = 262] = "ManifestNotFound";
|
||||
RvfErrorCode[RvfErrorCode["UnknownSegmentType"] = 263] = "UnknownSegmentType";
|
||||
RvfErrorCode[RvfErrorCode["AlignmentError"] = 264] = "AlignmentError";
|
||||
// Category 0x02: Query Errors
|
||||
RvfErrorCode[RvfErrorCode["DimensionMismatch"] = 512] = "DimensionMismatch";
|
||||
RvfErrorCode[RvfErrorCode["EmptyIndex"] = 513] = "EmptyIndex";
|
||||
RvfErrorCode[RvfErrorCode["MetricUnsupported"] = 514] = "MetricUnsupported";
|
||||
RvfErrorCode[RvfErrorCode["FilterParseError"] = 515] = "FilterParseError";
|
||||
RvfErrorCode[RvfErrorCode["KTooLarge"] = 516] = "KTooLarge";
|
||||
RvfErrorCode[RvfErrorCode["Timeout"] = 517] = "Timeout";
|
||||
// Category 0x03: Write Errors
|
||||
RvfErrorCode[RvfErrorCode["LockHeld"] = 768] = "LockHeld";
|
||||
RvfErrorCode[RvfErrorCode["LockStale"] = 769] = "LockStale";
|
||||
RvfErrorCode[RvfErrorCode["DiskFull"] = 770] = "DiskFull";
|
||||
RvfErrorCode[RvfErrorCode["FsyncFailed"] = 771] = "FsyncFailed";
|
||||
RvfErrorCode[RvfErrorCode["SegmentTooLarge"] = 772] = "SegmentTooLarge";
|
||||
RvfErrorCode[RvfErrorCode["ReadOnly"] = 773] = "ReadOnly";
|
||||
// Category 0x04: Tile Errors (WASM Microkernel)
|
||||
RvfErrorCode[RvfErrorCode["TileTrap"] = 1024] = "TileTrap";
|
||||
RvfErrorCode[RvfErrorCode["TileOom"] = 1025] = "TileOom";
|
||||
RvfErrorCode[RvfErrorCode["TileTimeout"] = 1026] = "TileTimeout";
|
||||
RvfErrorCode[RvfErrorCode["TileInvalidMsg"] = 1027] = "TileInvalidMsg";
|
||||
RvfErrorCode[RvfErrorCode["TileUnsupportedOp"] = 1028] = "TileUnsupportedOp";
|
||||
// Category 0x05: Crypto Errors
|
||||
RvfErrorCode[RvfErrorCode["KeyNotFound"] = 1280] = "KeyNotFound";
|
||||
RvfErrorCode[RvfErrorCode["KeyExpired"] = 1281] = "KeyExpired";
|
||||
RvfErrorCode[RvfErrorCode["DecryptFailed"] = 1282] = "DecryptFailed";
|
||||
RvfErrorCode[RvfErrorCode["AlgoUnsupported"] = 1283] = "AlgoUnsupported";
|
||||
// SDK-level errors (0xFF__)
|
||||
RvfErrorCode[RvfErrorCode["BackendNotFound"] = 65280] = "BackendNotFound";
|
||||
RvfErrorCode[RvfErrorCode["BackendInitFailed"] = 65281] = "BackendInitFailed";
|
||||
RvfErrorCode[RvfErrorCode["StoreClosed"] = 65282] = "StoreClosed";
|
||||
})(RvfErrorCode || (exports.RvfErrorCode = RvfErrorCode = {}));
|
||||
/** Human-readable labels for each error code. */
|
||||
const ERROR_MESSAGES = {
|
||||
[RvfErrorCode.Ok]: 'Operation succeeded',
|
||||
[RvfErrorCode.OkPartial]: 'Partial success (some items failed)',
|
||||
[RvfErrorCode.InvalidMagic]: 'Segment magic mismatch',
|
||||
[RvfErrorCode.InvalidVersion]: 'Unsupported segment version',
|
||||
[RvfErrorCode.InvalidChecksum]: 'Segment hash verification failed',
|
||||
[RvfErrorCode.InvalidSignature]: 'Cryptographic signature invalid',
|
||||
[RvfErrorCode.TruncatedSegment]: 'Segment payload shorter than declared',
|
||||
[RvfErrorCode.InvalidManifest]: 'Root manifest validation failed',
|
||||
[RvfErrorCode.ManifestNotFound]: 'No valid manifest in file',
|
||||
[RvfErrorCode.UnknownSegmentType]: 'Unrecognized segment type',
|
||||
[RvfErrorCode.AlignmentError]: 'Data not at expected 64-byte boundary',
|
||||
[RvfErrorCode.DimensionMismatch]: 'Query vector dimension != index dimension',
|
||||
[RvfErrorCode.EmptyIndex]: 'No index segments available',
|
||||
[RvfErrorCode.MetricUnsupported]: 'Requested distance metric not available',
|
||||
[RvfErrorCode.FilterParseError]: 'Invalid filter expression',
|
||||
[RvfErrorCode.KTooLarge]: 'Requested K exceeds available vectors',
|
||||
[RvfErrorCode.Timeout]: 'Query exceeded time budget',
|
||||
[RvfErrorCode.LockHeld]: 'Another writer holds the lock',
|
||||
[RvfErrorCode.LockStale]: 'Lock file exists but owner is dead',
|
||||
[RvfErrorCode.DiskFull]: 'Insufficient space for write',
|
||||
[RvfErrorCode.FsyncFailed]: 'Durable write (fsync) failed',
|
||||
[RvfErrorCode.SegmentTooLarge]: 'Segment exceeds 4 GB limit',
|
||||
[RvfErrorCode.ReadOnly]: 'Store opened in read-only mode',
|
||||
[RvfErrorCode.TileTrap]: 'WASM trap (OOB, unreachable, stack overflow)',
|
||||
[RvfErrorCode.TileOom]: 'Tile exceeded scratch memory',
|
||||
[RvfErrorCode.TileTimeout]: 'Tile computation exceeded time budget',
|
||||
[RvfErrorCode.TileInvalidMsg]: 'Malformed hub-tile message',
|
||||
[RvfErrorCode.TileUnsupportedOp]: 'Operation not available on this profile',
|
||||
[RvfErrorCode.KeyNotFound]: 'Referenced key_id not found',
|
||||
[RvfErrorCode.KeyExpired]: 'Key past valid_until timestamp',
|
||||
[RvfErrorCode.DecryptFailed]: 'Decryption or auth tag verification failed',
|
||||
[RvfErrorCode.AlgoUnsupported]: 'Cryptographic algorithm not implemented',
|
||||
[RvfErrorCode.BackendNotFound]: 'No suitable backend found (install @ruvector/rvf-node or @ruvector/rvf-wasm)',
|
||||
[RvfErrorCode.BackendInitFailed]: 'Backend initialization failed',
|
||||
[RvfErrorCode.StoreClosed]: 'Store has been closed',
|
||||
};
|
||||
/**
|
||||
* Custom error class for all RVF operations.
|
||||
*
|
||||
* Carries a typed `code` field for programmatic matching and a
|
||||
* human-readable `message`.
|
||||
*/
|
||||
class RvfError extends Error {
|
||||
/** Error category (high byte of the code). */
|
||||
get category() {
|
||||
return (this.code >> 8) & 0xff;
|
||||
}
|
||||
/** True when the category indicates a format-level (fatal) error. */
|
||||
get isFormatError() {
|
||||
return this.category === 0x01;
|
||||
}
|
||||
constructor(code, detail) {
|
||||
const base = ERROR_MESSAGES[code] ?? `RVF error 0x${code.toString(16).padStart(4, '0')}`;
|
||||
const message = detail ? `${base}: ${detail}` : base;
|
||||
super(message);
|
||||
this.name = 'RvfError';
|
||||
this.code = code;
|
||||
}
|
||||
/**
|
||||
* Create an RvfError from a native binding error.
|
||||
* Attempts to extract an error code from the message or object.
|
||||
*/
|
||||
static fromNative(err) {
|
||||
if (err instanceof RvfError)
|
||||
return err;
|
||||
if (err instanceof Error) {
|
||||
const codeMatch = err.message.match(/0x([0-9a-fA-F]{4})/);
|
||||
if (codeMatch) {
|
||||
const code = parseInt(codeMatch[1], 16);
|
||||
if (code in RvfErrorCode) {
|
||||
return new RvfError(code, err.message);
|
||||
}
|
||||
}
|
||||
return new RvfError(RvfErrorCode.BackendInitFailed, err.message);
|
||||
}
|
||||
return new RvfError(RvfErrorCode.BackendInitFailed, String(err));
|
||||
}
|
||||
}
|
||||
exports.RvfError = RvfError;
|
||||
//# sourceMappingURL=errors.js.map
|
||||
1
vendor/ruvector/npm/packages/rvf/dist/errors.js.map
vendored
Normal file
1
vendor/ruvector/npm/packages/rvf/dist/errors.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,IAAY,YAiDX;AAjDD,WAAY,YAAY;IACtB,yBAAyB;IACzB,2CAAW,CAAA;IACX,yDAAkB,CAAA;IAElB,+BAA+B;IAC/B,iEAAqB,CAAA;IACrB,qEAAuB,CAAA;IACvB,uEAAwB,CAAA;IACxB,yEAAyB,CAAA;IACzB,yEAAyB,CAAA;IACzB,uEAAwB,CAAA;IACxB,yEAAyB,CAAA;IACzB,6EAA2B,CAAA;IAC3B,qEAAuB,CAAA;IAEvB,8BAA8B;IAC9B,2EAA0B,CAAA;IAC1B,6DAAmB,CAAA;IACnB,2EAA0B,CAAA;IAC1B,yEAAyB,CAAA;IACzB,2DAAkB,CAAA;IAClB,uDAAgB,CAAA;IAEhB,8BAA8B;IAC9B,yDAAiB,CAAA;IACjB,2DAAkB,CAAA;IAClB,yDAAiB,CAAA;IACjB,+DAAoB,CAAA;IACpB,uEAAwB,CAAA;IACxB,yDAAiB,CAAA;IAEjB,gDAAgD;IAChD,0DAAiB,CAAA;IACjB,wDAAgB,CAAA;IAChB,gEAAoB,CAAA;IACpB,sEAAuB,CAAA;IACvB,4EAA0B,CAAA;IAE1B,+BAA+B;IAC/B,gEAAoB,CAAA;IACpB,8DAAmB,CAAA;IACnB,oEAAsB,CAAA;IACtB,wEAAwB,CAAA;IAExB,4BAA4B;IAC5B,yEAAwB,CAAA;IACxB,6EAA0B,CAAA;IAC1B,iEAAoB,CAAA;AACtB,CAAC,EAjDW,YAAY,4BAAZ,YAAY,QAiDvB;AAED,iDAAiD;AACjD,MAAM,cAAc,GAA2B;IAC7C,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,qBAAqB;IACxC,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,qCAAqC;IAC/D,CAA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AY,QAAQ;YAAE,OAAO,GAAG,CAAC;QACxC,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;YACzB,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;YAC1D,IAAI,SAAS,EAAE,CAAC;gBACd,MAAM,IAAI,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBACxC,IAAI,IAAI,IAAI,YAAY,EAAE,CAAC;oBACzB,OAAO,IAAI,QAAQ,CAAC,IAAoB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;gBACzD,CAAC;YACH,CAAC;YACD,OAAO,IAAI,QAAQ,CAAC,YAAY,CAAC,iBAAiB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QACnE,CAAC;QACD,OAAO,IAAI,QAAQ,CAAC,YAAY,CAAC,iBAAiB,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IACnE,CAAC;CACF;AAxCD,4BAwCC"}
|
||||
25
vendor/ruvector/npm/packages/rvf/dist/index.d.ts
vendored
Normal file
25
vendor/ruvector/npm/packages/rvf/dist/index.d.ts
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* @ruvector/rvf — Unified TypeScript SDK for the RuVector Format.
|
||||
*
|
||||
* Works with both the native Node.js backend (`@ruvector/rvf-node`) and
|
||||
* the browser WASM backend (`@ruvector/rvf-wasm`).
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { RvfDatabase } from '@ruvector/rvf';
|
||||
*
|
||||
* const db = await RvfDatabase.create('./my.rvf', { dimensions: 128 });
|
||||
* await db.ingestBatch([
|
||||
* { id: '1', vector: new Float32Array(128) },
|
||||
* ]);
|
||||
* const results = await db.query(new Float32Array(128), 10);
|
||||
* await db.close();
|
||||
* ```
|
||||
*/
|
||||
export type { DistanceMetric, CompressionProfile, HardwareProfile, RvfOptions, RvfFilterValue, RvfFilterExpr, RvfQueryOptions, RvfSearchResult, RvfIngestResult, RvfIngestEntry, RvfDeleteResult, RvfCompactionResult, CompactionState, RvfStatus, DerivationType, RvfKernelData, RvfEbpfData, RvfSegmentInfo, BackendType, RvfIndexStats, RvfWitnessResult, } from './types';
|
||||
export { RvfError, RvfErrorCode } from './errors';
|
||||
export type { RvfBackend } from './backend';
|
||||
export { NodeBackend, WasmBackend, resolveBackend } from './backend';
|
||||
export { RvfDatabase } from './database';
|
||||
export { RvfSolver } from '@ruvector/rvf-solver';
|
||||
export type { TrainOptions, TrainResult, AcceptanceOptions, AcceptanceManifest, AcceptanceModeResult, CycleMetrics, PolicyState, SkipMode, SkipModeStats, CompiledConfig, } from '@ruvector/rvf-solver';
|
||||
36
vendor/ruvector/npm/packages/rvf/dist/index.js
vendored
Normal file
36
vendor/ruvector/npm/packages/rvf/dist/index.js
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
/**
|
||||
* @ruvector/rvf — Unified TypeScript SDK for the RuVector Format.
|
||||
*
|
||||
* Works with both the native Node.js backend (`@ruvector/rvf-node`) and
|
||||
* the browser WASM backend (`@ruvector/rvf-wasm`).
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { RvfDatabase } from '@ruvector/rvf';
|
||||
*
|
||||
* const db = await RvfDatabase.create('./my.rvf', { dimensions: 128 });
|
||||
* await db.ingestBatch([
|
||||
* { id: '1', vector: new Float32Array(128) },
|
||||
* ]);
|
||||
* const results = await db.query(new Float32Array(128), 10);
|
||||
* await db.close();
|
||||
* ```
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RvfSolver = exports.RvfDatabase = exports.resolveBackend = exports.WasmBackend = exports.NodeBackend = exports.RvfErrorCode = exports.RvfError = void 0;
|
||||
// Re-export error types
|
||||
var errors_1 = require("./errors");
|
||||
Object.defineProperty(exports, "RvfError", { enumerable: true, get: function () { return errors_1.RvfError; } });
|
||||
Object.defineProperty(exports, "RvfErrorCode", { enumerable: true, get: function () { return errors_1.RvfErrorCode; } });
|
||||
var backend_1 = require("./backend");
|
||||
Object.defineProperty(exports, "NodeBackend", { enumerable: true, get: function () { return backend_1.NodeBackend; } });
|
||||
Object.defineProperty(exports, "WasmBackend", { enumerable: true, get: function () { return backend_1.WasmBackend; } });
|
||||
Object.defineProperty(exports, "resolveBackend", { enumerable: true, get: function () { return backend_1.resolveBackend; } });
|
||||
// Re-export the main database class
|
||||
var database_1 = require("./database");
|
||||
Object.defineProperty(exports, "RvfDatabase", { enumerable: true, get: function () { return database_1.RvfDatabase; } });
|
||||
// Re-export solver (AGI components)
|
||||
var rvf_solver_1 = require("@ruvector/rvf-solver");
|
||||
Object.defineProperty(exports, "RvfSolver", { enumerable: true, get: function () { return rvf_solver_1.RvfSolver; } });
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
vendor/ruvector/npm/packages/rvf/dist/index.js.map
vendored
Normal file
1
vendor/ruvector/npm/packages/rvf/dist/index.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AA2BH,wBAAwB;AACxB,mCAAkD;AAAzC,kGAAA,QAAQ,OAAA;AAAE,sGAAA,YAAY,OAAA;AAI/B,qCAAqE;AAA5D,sGAAA,WAAW,OAAA;AAAE,sGAAA,WAAW,OAAA;AAAE,yGAAA,cAAc,OAAA;AAEjD,oCAAoC;AACpC,uCAAyC;AAAhC,uGAAA,WAAW,OAAA;AAEpB,oCAAoC;AACpC,mDAAiD;AAAxC,uGAAA,SAAS,OAAA"}
|
||||
212
vendor/ruvector/npm/packages/rvf/dist/types.d.ts
vendored
Normal file
212
vendor/ruvector/npm/packages/rvf/dist/types.d.ts
vendored
Normal file
@@ -0,0 +1,212 @@
|
||||
/**
|
||||
* Distance metric for vector similarity search.
|
||||
*
|
||||
* - `l2` Squared Euclidean distance.
|
||||
* - `cosine` Cosine distance (1 - cosine_similarity).
|
||||
* - `dotproduct` Negated inner (dot) product.
|
||||
*/
|
||||
export type DistanceMetric = 'l2' | 'cosine' | 'dotproduct';
|
||||
/**
|
||||
* Compression profile for stored vectors.
|
||||
*
|
||||
* - `none` Raw fp32 vectors.
|
||||
* - `scalar` Scalar quantization (int8).
|
||||
* - `product` Product quantization.
|
||||
*/
|
||||
export type CompressionProfile = 'none' | 'scalar' | 'product';
|
||||
/**
|
||||
* Hardware profile selector.
|
||||
*
|
||||
* 0 = Generic, 1 = Core, 2 = Hot, 3 = Full.
|
||||
*/
|
||||
export type HardwareProfile = 0 | 1 | 2 | 3;
|
||||
/** Options for creating a new RVF store. */
|
||||
export interface RvfOptions {
|
||||
/** Vector dimensionality (required, must be > 0). */
|
||||
dimensions: number;
|
||||
/** Distance metric for similarity search. Default: `'l2'`. */
|
||||
metric?: DistanceMetric;
|
||||
/** Hardware profile identifier. Default: `0` (Generic). */
|
||||
profile?: HardwareProfile;
|
||||
/** Compression profile. Default: `'none'`. */
|
||||
compression?: CompressionProfile;
|
||||
/** Enable segment signing. Default: `false`. */
|
||||
signing?: boolean;
|
||||
/** HNSW M parameter: max edges per node per layer. Default: `16`. */
|
||||
m?: number;
|
||||
/** HNSW ef_construction: beam width during index build. Default: `200`. */
|
||||
efConstruction?: number;
|
||||
}
|
||||
/** Primitive value types usable in filter expressions. */
|
||||
export type RvfFilterValue = number | string | boolean;
|
||||
/**
|
||||
* A filter expression for metadata-based vector filtering.
|
||||
*
|
||||
* Leaf operators compare a `fieldId` against a literal `value`.
|
||||
* Composite operators combine sub-expressions with boolean logic.
|
||||
*/
|
||||
export type RvfFilterExpr = {
|
||||
op: 'eq';
|
||||
fieldId: number;
|
||||
value: RvfFilterValue;
|
||||
} | {
|
||||
op: 'ne';
|
||||
fieldId: number;
|
||||
value: RvfFilterValue;
|
||||
} | {
|
||||
op: 'lt';
|
||||
fieldId: number;
|
||||
value: RvfFilterValue;
|
||||
} | {
|
||||
op: 'le';
|
||||
fieldId: number;
|
||||
value: RvfFilterValue;
|
||||
} | {
|
||||
op: 'gt';
|
||||
fieldId: number;
|
||||
value: RvfFilterValue;
|
||||
} | {
|
||||
op: 'ge';
|
||||
fieldId: number;
|
||||
value: RvfFilterValue;
|
||||
} | {
|
||||
op: 'in';
|
||||
fieldId: number;
|
||||
values: RvfFilterValue[];
|
||||
} | {
|
||||
op: 'range';
|
||||
fieldId: number;
|
||||
low: RvfFilterValue;
|
||||
high: RvfFilterValue;
|
||||
} | {
|
||||
op: 'and';
|
||||
exprs: RvfFilterExpr[];
|
||||
} | {
|
||||
op: 'or';
|
||||
exprs: RvfFilterExpr[];
|
||||
} | {
|
||||
op: 'not';
|
||||
expr: RvfFilterExpr;
|
||||
};
|
||||
/** Options controlling a query operation. */
|
||||
export interface RvfQueryOptions {
|
||||
/** HNSW ef_search parameter (beam width during search). Default: `100`. */
|
||||
efSearch?: number;
|
||||
/** Optional metadata filter expression. */
|
||||
filter?: RvfFilterExpr;
|
||||
/** Query timeout in milliseconds (0 = no timeout). Default: `0`. */
|
||||
timeoutMs?: number;
|
||||
}
|
||||
/** A single search result: vector ID and distance. */
|
||||
export interface RvfSearchResult {
|
||||
/** The vector's unique identifier (string-encoded u64). */
|
||||
id: string;
|
||||
/** Distance from the query vector (lower = more similar). */
|
||||
distance: number;
|
||||
}
|
||||
/** Result of a batch ingest operation. */
|
||||
export interface RvfIngestResult {
|
||||
/** Number of vectors successfully ingested. */
|
||||
accepted: number;
|
||||
/** Number of vectors rejected. */
|
||||
rejected: number;
|
||||
/** Manifest epoch after the ingest commit. */
|
||||
epoch: number;
|
||||
}
|
||||
/** Result of a delete operation. */
|
||||
export interface RvfDeleteResult {
|
||||
/** Number of vectors soft-deleted. */
|
||||
deleted: number;
|
||||
/** Manifest epoch after the delete commit. */
|
||||
epoch: number;
|
||||
}
|
||||
/** Result of a compaction operation. */
|
||||
export interface RvfCompactionResult {
|
||||
/** Number of segments compacted. */
|
||||
segmentsCompacted: number;
|
||||
/** Bytes of dead space reclaimed. */
|
||||
bytesReclaimed: number;
|
||||
/** Manifest epoch after compaction commit. */
|
||||
epoch: number;
|
||||
}
|
||||
/** Compaction state as reported in store status. */
|
||||
export type CompactionState = 'idle' | 'running' | 'emergency';
|
||||
/** A snapshot of the store's current state. */
|
||||
export interface RvfStatus {
|
||||
/** Total number of live (non-deleted) vectors. */
|
||||
totalVectors: number;
|
||||
/** Total number of segments in the file. */
|
||||
totalSegments: number;
|
||||
/** Total file size in bytes. */
|
||||
fileSizeBytes: number;
|
||||
/** Current manifest epoch. */
|
||||
epoch: number;
|
||||
/** Hardware profile identifier. */
|
||||
profileId: number;
|
||||
/** Current compaction state. */
|
||||
compactionState: CompactionState;
|
||||
/** Ratio of dead space to total (0.0 - 1.0). */
|
||||
deadSpaceRatio: number;
|
||||
/** Whether the store is open in read-only mode. */
|
||||
readOnly: boolean;
|
||||
}
|
||||
/** A single entry for batch ingestion. */
|
||||
export interface RvfIngestEntry {
|
||||
/** Unique vector identifier. */
|
||||
id: string;
|
||||
/** The embedding vector (must match store dimensions). */
|
||||
vector: Float32Array | number[];
|
||||
/** Optional per-vector metadata fields. */
|
||||
metadata?: Record<string, RvfFilterValue>;
|
||||
}
|
||||
/** Derivation type for creating derived stores. */
|
||||
export type DerivationType = 'filter' | 'merge' | 'snapshot' | 'transform';
|
||||
/** Data returned from kernel extraction. */
|
||||
export interface RvfKernelData {
|
||||
/** Serialized KernelHeader bytes. */
|
||||
header: Uint8Array;
|
||||
/** Raw kernel image bytes. */
|
||||
image: Uint8Array;
|
||||
}
|
||||
/** Data returned from eBPF extraction. */
|
||||
export interface RvfEbpfData {
|
||||
/** Serialized EbpfHeader bytes. */
|
||||
header: Uint8Array;
|
||||
/** Program bytecode + optional BTF. */
|
||||
payload: Uint8Array;
|
||||
}
|
||||
/** Information about a segment in the store. */
|
||||
export interface RvfSegmentInfo {
|
||||
/** Segment ID. */
|
||||
id: number;
|
||||
/** File offset of the segment. */
|
||||
offset: number;
|
||||
/** Payload length in bytes. */
|
||||
payloadLength: number;
|
||||
/** Segment type name (e.g. "vec", "manifest", "kernel"). */
|
||||
segType: string;
|
||||
}
|
||||
/** Identifies which backend implementation to use. */
|
||||
export type BackendType = 'node' | 'wasm' | 'auto';
|
||||
/** HNSW index statistics. */
|
||||
export interface RvfIndexStats {
|
||||
/** Number of indexed vectors. */
|
||||
indexedVectors: number;
|
||||
/** Number of HNSW layers. */
|
||||
layers: number;
|
||||
/** M parameter (max edges per node per layer). */
|
||||
m: number;
|
||||
/** ef_construction parameter. */
|
||||
efConstruction: number;
|
||||
/** Whether the index needs rebuilding. */
|
||||
needsRebuild: boolean;
|
||||
}
|
||||
/** Result of witness chain verification. */
|
||||
export interface RvfWitnessResult {
|
||||
/** Whether the chain is valid. */
|
||||
valid: boolean;
|
||||
/** Number of entries in the chain. */
|
||||
entries: number;
|
||||
/** Error message if invalid. */
|
||||
error?: string;
|
||||
}
|
||||
3
vendor/ruvector/npm/packages/rvf/dist/types.js
vendored
Normal file
3
vendor/ruvector/npm/packages/rvf/dist/types.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=types.js.map
|
||||
1
vendor/ruvector/npm/packages/rvf/dist/types.js.map
vendored
Normal file
1
vendor/ruvector/npm/packages/rvf/dist/types.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
||||
Reference in New Issue
Block a user