mirror of
https://github.com/ruvnet/RuView
synced 2026-08-08 20:11:43 +00:00
Squashed 'vendor/ruvector/' content from commit b64c2172
git-subtree-dir: vendor/ruvector git-subtree-split: b64c21726f2bb37286d9ee36a7869fef60cc6900
This commit is contained in:
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @ruvector/core - CommonJS wrapper
|
||||
*
|
||||
* This file provides CommonJS compatibility for projects using require()
|
||||
*/
|
||||
/**
|
||||
* Distance metric for similarity calculation
|
||||
*/
|
||||
export declare enum DistanceMetric {
|
||||
/** Euclidean (L2) distance */
|
||||
Euclidean = "euclidean",
|
||||
/** Cosine similarity (1 - cosine distance) */
|
||||
Cosine = "cosine",
|
||||
/** Dot product similarity */
|
||||
DotProduct = "dot"
|
||||
}
|
||||
//# sourceMappingURL=index.cjs.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.cjs.d.ts","sourceRoot":"","sources":["index.cjs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH;;GAEG;AACH,oBAAY,cAAc;IACxB,8BAA8B;IAC9B,SAAS,cAAc;IACvB,8CAA8C;IAC9C,MAAM,WAAW;IACjB,6BAA6B;IAC7B,UAAU,QAAQ;CACnB"}
|
||||
@@ -0,0 +1,101 @@
|
||||
"use strict";
|
||||
/**
|
||||
* @ruvector/core - CommonJS wrapper
|
||||
*
|
||||
* This file provides CommonJS compatibility for projects using require()
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DistanceMetric = void 0;
|
||||
const node_os_1 = require("node:os");
|
||||
/**
|
||||
* Distance metric for similarity calculation
|
||||
*/
|
||||
var DistanceMetric;
|
||||
(function (DistanceMetric) {
|
||||
/** Euclidean (L2) distance */
|
||||
DistanceMetric["Euclidean"] = "euclidean";
|
||||
/** Cosine similarity (1 - cosine distance) */
|
||||
DistanceMetric["Cosine"] = "cosine";
|
||||
/** Dot product similarity */
|
||||
DistanceMetric["DotProduct"] = "dot";
|
||||
})(DistanceMetric || (exports.DistanceMetric = DistanceMetric = {}));
|
||||
/**
|
||||
* Get platform-specific package name
|
||||
*/
|
||||
function getPlatformPackage() {
|
||||
const plat = (0, node_os_1.platform)();
|
||||
const architecture = (0, node_os_1.arch)();
|
||||
// Map Node.js platform names to package names
|
||||
const packageMap = {
|
||||
'linux-x64': 'ruvector-core-linux-x64-gnu',
|
||||
'linux-arm64': 'ruvector-core-linux-arm64-gnu',
|
||||
'darwin-x64': 'ruvector-core-darwin-x64',
|
||||
'darwin-arm64': 'ruvector-core-darwin-arm64',
|
||||
'win32-x64': 'ruvector-core-win32-x64-msvc',
|
||||
};
|
||||
const key = `${plat}-${architecture}`;
|
||||
const packageName = packageMap[key];
|
||||
if (!packageName) {
|
||||
throw new Error(`Unsupported platform: ${plat}-${architecture}. ` +
|
||||
`Supported platforms: ${Object.keys(packageMap).join(', ')}`);
|
||||
}
|
||||
return packageName;
|
||||
}
|
||||
/**
|
||||
* Load the native binding for the current platform
|
||||
*/
|
||||
function loadNativeBinding() {
|
||||
const packageName = getPlatformPackage();
|
||||
try {
|
||||
// Try to require the platform-specific package
|
||||
return require(packageName);
|
||||
}
|
||||
catch (error) {
|
||||
// Fallback: try loading from local platforms directory
|
||||
try {
|
||||
const plat = (0, node_os_1.platform)();
|
||||
const architecture = (0, node_os_1.arch)();
|
||||
const platformKey = `${plat}-${architecture}`;
|
||||
const platformMap = {
|
||||
'linux-x64': 'linux-x64-gnu',
|
||||
'linux-arm64': 'linux-arm64-gnu',
|
||||
'darwin-x64': 'darwin-x64',
|
||||
'darwin-arm64': 'darwin-arm64',
|
||||
'win32-x64': 'win32-x64-msvc',
|
||||
};
|
||||
const localPath = `../platforms/${platformMap[platformKey]}/ruvector.node`;
|
||||
return require(localPath);
|
||||
}
|
||||
catch (fallbackError) {
|
||||
throw new Error(`Failed to load native binding: ${error.message}\n` +
|
||||
`Fallback also failed: ${fallbackError.message}\n` +
|
||||
`Platform: ${(0, node_os_1.platform)()}-${(0, node_os_1.arch)()}\n` +
|
||||
`Expected package: ${packageName}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Load the native module
|
||||
const nativeBinding = loadNativeBinding();
|
||||
// Try to load optional attention module
|
||||
let attention = null;
|
||||
try {
|
||||
attention = require('@ruvector/attention');
|
||||
}
|
||||
catch {
|
||||
// Attention module not installed - this is optional
|
||||
}
|
||||
// Export everything from the native binding
|
||||
module.exports = nativeBinding;
|
||||
// Add VectorDB alias (native exports as VectorDb)
|
||||
if (nativeBinding.VectorDb && !nativeBinding.VectorDB) {
|
||||
module.exports.VectorDB = nativeBinding.VectorDb;
|
||||
}
|
||||
// Also export as default
|
||||
module.exports.default = nativeBinding;
|
||||
// Re-export DistanceMetric
|
||||
module.exports.DistanceMetric = DistanceMetric;
|
||||
// Export attention if available
|
||||
if (attention) {
|
||||
module.exports.attention = attention;
|
||||
}
|
||||
//# sourceMappingURL=index.cjs.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.cjs.js","sourceRoot":"","sources":["index.cjs.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,qCAAyC;AAMzC;;GAEG;AACH,IAAY,cAOX;AAPD,WAAY,cAAc;IACxB,8BAA8B;IAC9B,yCAAuB,CAAA;IACvB,8CAA8C;IAC9C,mCAAiB,CAAA;IACjB,6BAA6B;IAC7B,oCAAkB,CAAA;AACpB,CAAC,EAPW,cAAc,8BAAd,cAAc,QAOzB;AAED;;GAEG;AACH,SAAS,kBAAkB;IACzB,MAAM,IAAI,GAAG,IAAA,kBAAQ,GAAc,CAAC;IACpC,MAAM,YAAY,GAAG,IAAA,cAAI,GAAkB,CAAC;IAE5C,8CAA8C;IAC9C,MAAM,UAAU,GAA2B;QACzC,WAAW,EAAE,6BAA6B;QAC1C,aAAa,EAAE,+BAA+B;QAC9C,YAAY,EAAE,0BAA0B;QACxC,cAAc,EAAE,4BAA4B;QAC5C,WAAW,EAAE,8BAA8B;KAC5C,CAAC;IAEF,MAA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AAI;gBACrC,qBAAqB,WAAW,EAAE,CACnC,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC;AAED,yBAAyB;AACzB,MAAM,aAAa,GAAG,iBAAiB,EAAE,CAAC;AAE1C,wCAAwC;AACxC,IAAI,SAAS,GAAG,IAAI,CAAC;AACrB,IAAI,CAAC;IACH,SAAS,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAC7C,CAAC;AAAC,MAAM,CAAC;IACP,oDAAoD;AACtD,CAAC;AAED,4CAA4C;AAC5C,MAAM,CAAC,OAAO,GAAG,aAAa,CAAC;AAE/B,kDAAkD;AAClD,IAAI,aAAa,CAAC,QAAQ,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;IACtD,MAAM,CAAC,OAAO,CAAC,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC;AACnD,CAAC;AAED,yBAAyB;AACzB,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,aAAa,CAAC;AAEvC,2BAA2B;AAC3B,MAAM,CAAC,OAAO,CAAC,cAAc,GAAG,cAAc,CAAC;AAE/C,gCAAgC;AAChC,IAAI,SAAS,EAAE,CAAC;IACd,MAAM,CAAC,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;AACvC,CAAC"}
|
||||
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* @ruvector/core - CommonJS wrapper
|
||||
*
|
||||
* This file provides CommonJS compatibility for projects using require()
|
||||
*/
|
||||
|
||||
import { platform, arch } from 'node:os';
|
||||
|
||||
// Platform detection types
|
||||
type Platform = 'linux' | 'darwin' | 'win32';
|
||||
type Architecture = 'x64' | 'arm64';
|
||||
|
||||
/**
|
||||
* Distance metric for similarity calculation
|
||||
*/
|
||||
export enum DistanceMetric {
|
||||
/** Euclidean (L2) distance */
|
||||
Euclidean = 'euclidean',
|
||||
/** Cosine similarity (1 - cosine distance) */
|
||||
Cosine = 'cosine',
|
||||
/** Dot product similarity */
|
||||
DotProduct = 'dot',
|
||||
}
|
||||
|
||||
/**
|
||||
* Get platform-specific package name
|
||||
*/
|
||||
function getPlatformPackage(): string {
|
||||
const plat = platform() as Platform;
|
||||
const architecture = arch() as Architecture;
|
||||
|
||||
// Map Node.js platform names to package names
|
||||
const packageMap: Record<string, string> = {
|
||||
'linux-x64': 'ruvector-core-linux-x64-gnu',
|
||||
'linux-arm64': 'ruvector-core-linux-arm64-gnu',
|
||||
'darwin-x64': 'ruvector-core-darwin-x64',
|
||||
'darwin-arm64': 'ruvector-core-darwin-arm64',
|
||||
'win32-x64': 'ruvector-core-win32-x64-msvc',
|
||||
};
|
||||
|
||||
const key = `${plat}-${architecture}`;
|
||||
const packageName = packageMap[key];
|
||||
|
||||
if (!packageName) {
|
||||
throw new Error(
|
||||
`Unsupported platform: ${plat}-${architecture}. ` +
|
||||
`Supported platforms: ${Object.keys(packageMap).join(', ')}`
|
||||
);
|
||||
}
|
||||
|
||||
return packageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the native binding for the current platform
|
||||
*/
|
||||
function loadNativeBinding() {
|
||||
const packageName = getPlatformPackage();
|
||||
|
||||
try {
|
||||
// Try to require the platform-specific package
|
||||
return require(packageName);
|
||||
} catch (error: any) {
|
||||
// Fallback: try loading from local platforms directory
|
||||
try {
|
||||
const plat = platform() as Platform;
|
||||
const architecture = arch() as Architecture;
|
||||
const platformKey = `${plat}-${architecture}`;
|
||||
const platformMap: Record<string, string> = {
|
||||
'linux-x64': 'linux-x64-gnu',
|
||||
'linux-arm64': 'linux-arm64-gnu',
|
||||
'darwin-x64': 'darwin-x64',
|
||||
'darwin-arm64': 'darwin-arm64',
|
||||
'win32-x64': 'win32-x64-msvc',
|
||||
};
|
||||
const localPath = `../platforms/${platformMap[platformKey]}/ruvector.node`;
|
||||
return require(localPath);
|
||||
} catch (fallbackError: any) {
|
||||
throw new Error(
|
||||
`Failed to load native binding: ${error.message}\n` +
|
||||
`Fallback also failed: ${fallbackError.message}\n` +
|
||||
`Platform: ${platform()}-${arch()}\n` +
|
||||
`Expected package: ${packageName}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load the native module
|
||||
const nativeBinding = loadNativeBinding();
|
||||
|
||||
// Try to load optional attention module
|
||||
let attention = null;
|
||||
try {
|
||||
attention = require('@ruvector/attention');
|
||||
} catch {
|
||||
// Attention module not installed - this is optional
|
||||
}
|
||||
|
||||
// Export everything from the native binding
|
||||
module.exports = nativeBinding;
|
||||
|
||||
// Add VectorDB alias (native exports as VectorDb)
|
||||
if (nativeBinding.VectorDb && !nativeBinding.VectorDB) {
|
||||
module.exports.VectorDB = nativeBinding.VectorDb;
|
||||
}
|
||||
|
||||
// Also export as default
|
||||
module.exports.default = nativeBinding;
|
||||
|
||||
// Re-export DistanceMetric
|
||||
module.exports.DistanceMetric = DistanceMetric;
|
||||
|
||||
// Export attention if available
|
||||
if (attention) {
|
||||
module.exports.attention = attention;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH;;GAEG;AACH,oBAAY,cAAc;IACxB,8BAA8B;IAC9B,SAAS,cAAc;IACvB,gDAAgD;IAChD,MAAM,WAAW;IACjB,2DAA2D;IAC3D,UAAU,eAAe;IACzB,8BAA8B;IAC9B,SAAS,cAAc;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,wBAAwB;IACxB,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;IAC/C,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,CAAC,CAAC,EAAE,MAAM,CAAC;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,0CAA0C;IAC1C,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,yDAAyD;IACzD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mDAAmD;IACnD,Q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AW,IAAI;oBACpD,oBAAoB,WAAW,sBAAsB,WAAW,IAAI;oBACpE,kEAAkE,WAAW,EAAE,CAChF,CAAC;YACJ,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,kCAAkC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;AACH,CAAC;AAED,0BAA0B;AAC1B,MAAM,aAAa,GAAG,iBAAiB,EAAE,CAAC;AAE1C,qDAAqD;AACrD,4FAA4F;AAC/E,QAAA,QAAQ,GAAI,aAAqB,CAAC,QAAQ,IAAI,aAAa,CAAC,QAAQ,CAAC;AACrE,QAAA,iBAAiB,GAAG,aAAa,CAAC,iBAAiB,CAAC;AACpD,QAAA,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC;AAChC,QAAA,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC;AAC5B,QAAA,UAAU,GAAG,aAAa,CAAC,UAAU,CAAC;AACtC,QAAA,SAAS,GAAG,aAAa,CAAC,SAAS,CAAC;AAEjD,wCAAwC;AACxC,IAAI,SAAS,GAAQ,IAAI,CAAC;AAQjB,8BAAS;AAPlB,IAAI,CAAC;IACH,oBAAA,SAAS,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAC7C,CAAC;AAAC,MAAM,CAAC;IACP,oDAAoD;AACtD,CAAC;AAKD,iBAAiB;AACjB,kBAAe;IACb,QAAQ,EAAR,gBAAQ;IACR,iBAAiB,EAAjB,yBAAiB;IACjB,OAAO,EAAP,eAAO;IACP,KAAK,EAAL,aAAK;IACL,UAAU,EAAV,kBAAU;IACV,SAAS,EAAT,iBAAS;IACT,cAAc;IACd,iCAAiC;IACjC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;CACpC,CAAC"}
|
||||
@@ -0,0 +1,396 @@
|
||||
/**
|
||||
* @ruvector/core - High-performance Rust vector database for Node.js
|
||||
*
|
||||
* Automatically detects platform and loads the appropriate native binding.
|
||||
*/
|
||||
|
||||
import { platform, arch } from 'node:os';
|
||||
import { createRequire } from 'node:module';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
// Platform detection types
|
||||
type Platform = 'linux' | 'darwin' | 'win32';
|
||||
type Architecture = 'x64' | 'arm64';
|
||||
|
||||
/**
|
||||
* Distance metric for similarity calculation
|
||||
*/
|
||||
export enum DistanceMetric {
|
||||
/** Euclidean (L2) distance */
|
||||
Euclidean = 'Euclidean',
|
||||
/** Cosine similarity (converted to distance) */
|
||||
Cosine = 'Cosine',
|
||||
/** Dot product (converted to distance for maximization) */
|
||||
DotProduct = 'DotProduct',
|
||||
/** Manhattan (L1) distance */
|
||||
Manhattan = 'Manhattan'
|
||||
}
|
||||
|
||||
/**
|
||||
* Quantization configuration
|
||||
*/
|
||||
export interface QuantizationConfig {
|
||||
/** Quantization type */
|
||||
type: 'none' | 'scalar' | 'product' | 'binary';
|
||||
/** Number of subspaces (for product quantization) */
|
||||
subspaces?: number;
|
||||
/** Codebook size (for product quantization) */
|
||||
k?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* HNSW index configuration
|
||||
*/
|
||||
export interface HnswConfig {
|
||||
/** Number of connections per layer (M) */
|
||||
m?: number;
|
||||
/** Size of dynamic candidate list during construction */
|
||||
efConstruction?: number;
|
||||
/** Size of dynamic candidate list during search */
|
||||
efSearch?: number;
|
||||
/** Maximum number of elements */
|
||||
maxElements?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Database configuration options
|
||||
*/
|
||||
export interface DbOptions {
|
||||
/** Vector dimensions */
|
||||
dimensions: number;
|
||||
/** Distance metric */
|
||||
distanceMetric?: DistanceMetric;
|
||||
/** Storage path */
|
||||
storagePath?: string;
|
||||
/** HNSW configuration */
|
||||
hnswConfig?: HnswConfig;
|
||||
/** Quantization configuration */
|
||||
quantization?: QuantizationConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vector entry
|
||||
*/
|
||||
export interface VectorEntry {
|
||||
/** Optional ID (auto-generated if not provided) */
|
||||
id?: string;
|
||||
/** Vector data as Float32Array or array of numbers */
|
||||
vector: Float32Array | number[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Search query parameters
|
||||
*/
|
||||
export interface SearchQuery {
|
||||
/** Query vector as Float32Array or array of numbers */
|
||||
vector: Float32Array | number[];
|
||||
/** Number of results to return (top-k) */
|
||||
k: number;
|
||||
/** Optional ef_search parameter for HNSW */
|
||||
efSearch?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search result with similarity score
|
||||
*/
|
||||
export interface SearchResult {
|
||||
/** Vector ID */
|
||||
id: string;
|
||||
/** Distance/similarity score (lower is better for distance metrics) */
|
||||
score: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* High-performance vector database with HNSW indexing
|
||||
*/
|
||||
export interface VectorDB {
|
||||
/**
|
||||
* Insert a vector entry into the database
|
||||
* @param entry Vector entry to insert
|
||||
* @returns Promise resolving to the ID of the inserted vector
|
||||
*/
|
||||
insert(entry: VectorEntry): Promise<string>;
|
||||
|
||||
/**
|
||||
* Insert multiple vectors in a batch
|
||||
* @param entries Array of vector entries to insert
|
||||
* @returns Promise resolving to an array of IDs for the inserted vectors
|
||||
*/
|
||||
insertBatch(entries: VectorEntry[]): Promise<string[]>;
|
||||
|
||||
/**
|
||||
* Search for similar vectors
|
||||
* @param query Search query parameters
|
||||
* @returns Promise resolving to an array of search results sorted by similarity
|
||||
*/
|
||||
search(query: SearchQuery): Promise<SearchResult[]>;
|
||||
|
||||
/**
|
||||
* Delete a vector by ID
|
||||
* @param id Vector ID to delete
|
||||
* @returns Promise resolving to true if deleted, false if not found
|
||||
*/
|
||||
delete(id: string): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Get a vector by ID
|
||||
* @param id Vector ID to retrieve
|
||||
* @returns Promise resolving to the vector entry if found, null otherwise
|
||||
*/
|
||||
get(id: string): Promise<VectorEntry | null>;
|
||||
|
||||
/**
|
||||
* Get the number of vectors in the database
|
||||
* @returns Promise resolving to the number of vectors
|
||||
*/
|
||||
len(): Promise<number>;
|
||||
|
||||
/**
|
||||
* Check if the database is empty
|
||||
* @returns Promise resolving to true if empty, false otherwise
|
||||
*/
|
||||
isEmpty(): Promise<boolean>;
|
||||
}
|
||||
|
||||
/**
|
||||
* VectorDB constructor interface
|
||||
*/
|
||||
export interface VectorDBConstructor {
|
||||
new(options: DbOptions): VectorDB;
|
||||
withDimensions(dimensions: number): VectorDB;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter for metadata-based search
|
||||
*/
|
||||
export interface Filter {
|
||||
/** Field name to filter on */
|
||||
field: string;
|
||||
/** Operator: "eq", "ne", "gt", "gte", "lt", "lte", "in", "match" */
|
||||
operator: 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'match';
|
||||
/** Value to compare against (JSON string) */
|
||||
value: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collection configuration
|
||||
*/
|
||||
export interface CollectionConfig {
|
||||
/** Vector dimensions */
|
||||
dimensions: number;
|
||||
/** Distance metric */
|
||||
distanceMetric?: DistanceMetric;
|
||||
/** HNSW configuration */
|
||||
hnswConfig?: HnswConfig;
|
||||
/** Quantization configuration */
|
||||
quantization?: QuantizationConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collection statistics
|
||||
*/
|
||||
export interface CollectionStats {
|
||||
/** Number of vectors in the collection */
|
||||
vectorsCount: number;
|
||||
/** Disk space used in bytes */
|
||||
diskSizeBytes: number;
|
||||
/** RAM space used in bytes */
|
||||
ramSizeBytes: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collection alias
|
||||
*/
|
||||
export interface Alias {
|
||||
/** Alias name */
|
||||
alias: string;
|
||||
/** Collection name */
|
||||
collection: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Health response
|
||||
*/
|
||||
export interface HealthResponse {
|
||||
/** Status: "healthy", "degraded", or "unhealthy" */
|
||||
status: 'healthy' | 'degraded' | 'unhealthy';
|
||||
/** Version string */
|
||||
version: string;
|
||||
/** Uptime in seconds */
|
||||
uptimeSeconds: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collection manager for multi-collection support
|
||||
*/
|
||||
export interface CollectionManager {
|
||||
/**
|
||||
* Create a new collection
|
||||
* @param name Collection name
|
||||
* @param config Collection configuration
|
||||
*/
|
||||
createCollection(name: string, config: CollectionConfig): Promise<void>;
|
||||
|
||||
/**
|
||||
* List all collections
|
||||
* @returns Array of collection names
|
||||
*/
|
||||
listCollections(): Promise<string[]>;
|
||||
|
||||
/**
|
||||
* Delete a collection
|
||||
* @param name Collection name to delete
|
||||
*/
|
||||
deleteCollection(name: string): Promise<void>;
|
||||
|
||||
/**
|
||||
* Get collection statistics
|
||||
* @param name Collection name
|
||||
* @returns Collection statistics
|
||||
*/
|
||||
getStats(name: string): Promise<CollectionStats>;
|
||||
|
||||
/**
|
||||
* Create an alias for a collection
|
||||
* @param alias Alias name
|
||||
* @param collection Collection name
|
||||
*/
|
||||
createAlias(alias: string, collection: string): Promise<void>;
|
||||
|
||||
/**
|
||||
* Delete an alias
|
||||
* @param alias Alias name to delete
|
||||
*/
|
||||
deleteAlias(alias: string): Promise<void>;
|
||||
|
||||
/**
|
||||
* List all aliases
|
||||
* @returns Array of alias mappings
|
||||
*/
|
||||
listAliases(): Promise<Alias[]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* CollectionManager constructor interface
|
||||
*/
|
||||
export interface CollectionManagerConstructor {
|
||||
new(basePath?: string): CollectionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Native binding interface
|
||||
*/
|
||||
export interface NativeBinding {
|
||||
VectorDB: VectorDBConstructor;
|
||||
CollectionManager: CollectionManagerConstructor;
|
||||
version(): string;
|
||||
hello(): string;
|
||||
getMetrics(): string;
|
||||
getHealth(): HealthResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect the current platform and architecture
|
||||
*/
|
||||
function detectPlatform(): { platform: Platform; arch: Architecture; packageName: string } {
|
||||
const currentPlatform = platform() as Platform;
|
||||
const currentArch = arch() as Architecture;
|
||||
|
||||
// Map platform and architecture to package names
|
||||
const platformMap: Record<string, string> = {
|
||||
'linux-x64': '@ruvector/core-linux-x64-gnu',
|
||||
'linux-arm64': '@ruvector/core-linux-arm64-gnu',
|
||||
'darwin-x64': '@ruvector/core-darwin-x64',
|
||||
'darwin-arm64': '@ruvector/core-darwin-arm64',
|
||||
'win32-x64': '@ruvector/core-win32-x64-msvc'
|
||||
};
|
||||
|
||||
const key = `${currentPlatform}-${currentArch}`;
|
||||
const packageName = platformMap[key];
|
||||
|
||||
if (!packageName) {
|
||||
throw new Error(
|
||||
`Unsupported platform: ${currentPlatform}-${currentArch}. ` +
|
||||
`Supported platforms: ${Object.keys(platformMap).join(', ')}`
|
||||
);
|
||||
}
|
||||
|
||||
return { platform: currentPlatform, arch: currentArch, packageName };
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the native binding for the current platform
|
||||
*/
|
||||
function loadNativeBinding(): NativeBinding {
|
||||
const currentPlatform = platform();
|
||||
const currentArch = arch();
|
||||
const platformKey = `${currentPlatform}-${currentArch}`;
|
||||
|
||||
try {
|
||||
// Try to load from native directory first (for direct builds)
|
||||
// Use the wrapper index.cjs if it exists, otherwise load the .node file directly
|
||||
try {
|
||||
const nativeBinding = require(`../native/${platformKey}/index.cjs`) as NativeBinding;
|
||||
return nativeBinding;
|
||||
} catch {
|
||||
const nativeBinding = require(`../native/${platformKey}/ruvector.node`) as NativeBinding;
|
||||
return nativeBinding;
|
||||
}
|
||||
} catch (error) {
|
||||
// Fallback to platform-specific packages
|
||||
const { packageName } = detectPlatform();
|
||||
|
||||
try {
|
||||
const nativeBinding = require(packageName) as NativeBinding;
|
||||
return nativeBinding;
|
||||
} catch (packageError) {
|
||||
// Provide helpful error message
|
||||
const err = packageError as NodeJS.ErrnoException;
|
||||
if (err.code === 'MODULE_NOT_FOUND') {
|
||||
throw new Error(
|
||||
`Failed to load native binding for ${platformKey}. ` +
|
||||
`Tried: ../native/${platformKey}/ruvector.node and ${packageName}. ` +
|
||||
`Please ensure the package is installed by running: npm install ${packageName}`
|
||||
);
|
||||
}
|
||||
throw new Error(`Failed to load native binding: ${err.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load the native binding
|
||||
const nativeBinding = loadNativeBinding();
|
||||
|
||||
// Re-export the VectorDB class and utility functions
|
||||
// Note: NAPI-RS exports as VectorDb (lowercase d), we re-export as VectorDB for consistency
|
||||
export const VectorDB = (nativeBinding as any).VectorDb || nativeBinding.VectorDB;
|
||||
export const CollectionManager = nativeBinding.CollectionManager;
|
||||
export const version = nativeBinding.version;
|
||||
export const hello = nativeBinding.hello;
|
||||
export const getMetrics = nativeBinding.getMetrics;
|
||||
export const getHealth = nativeBinding.getHealth;
|
||||
|
||||
// Try to load optional attention module
|
||||
let attention: any = null;
|
||||
try {
|
||||
attention = require('@ruvector/attention');
|
||||
} catch {
|
||||
// Attention module not installed - this is optional
|
||||
}
|
||||
|
||||
// Export attention if available
|
||||
export { attention };
|
||||
|
||||
// Default export
|
||||
export default {
|
||||
VectorDB,
|
||||
CollectionManager,
|
||||
version,
|
||||
hello,
|
||||
getMetrics,
|
||||
getHealth,
|
||||
DistanceMetric,
|
||||
// Include attention if available
|
||||
...(attention ? { attention } : {})
|
||||
};
|
||||
Reference in New Issue
Block a user