Skip to main content

Overview

Complete TypeScript type definitions for the VecLabs SDK. All types are exported from the main package.
import type {
  Network,
  DistanceMetric,
  SolVecConfig,
  UpsertRecord,
  QueryOptions,
  QueryMatch,
  QueryResponse,
  UpsertResponse,
  CollectionStats,
  VerificationResult,
  CollectionConfig
} from 'solvec';

Configuration Types

Network

Solana network identifier.
type Network = "mainnet-beta" | "devnet" | "localnet";
mainnet-beta
string
Solana production network
devnet
string
Solana development/testing network (recommended for development)
localnet
string
Local Solana test validator

DistanceMetric

Vector similarity metric.
type DistanceMetric = "cosine" | "euclidean" | "dot";
cosine
string
Cosine similarity (recommended for most use cases). Range: [-1, 1], where 1 = identical direction.
euclidean
string
Euclidean (L2) distance. Measures absolute distance in vector space.
dot
string
Dot product similarity. Fast but sensitive to vector magnitude.

SolVecConfig

Configuration for initializing the SolVec client.
interface SolVecConfig {
  network: Network;
  walletPath?: string;
  rpcUrl?: string;
}
network
Network
required
Solana network to connect to
walletPath
string
Path to Solana wallet keypair JSON file. Required for write operations.
rpcUrl
string
Custom RPC endpoint URL. Falls back to default URLs if not provided.

Example

const config: SolVecConfig = {
  network: 'devnet',
  walletPath: './wallet.json',
  rpcUrl: 'https://api.devnet.solana.com'
};

CollectionConfig

Configuration for creating or accessing a collection.
interface CollectionConfig {
  dimensions?: number;
  metric?: DistanceMetric;
}
dimensions
number
default:"1536"
Vector dimensionality. Common values:
  • 1536: OpenAI text-embedding-ada-002
  • 768: sentence-transformers/all-mpnet-base-v2
  • 384: sentence-transformers/all-MiniLM-L6-v2
metric
DistanceMetric
default:"cosine"
Distance metric for similarity calculations

Example

const config: CollectionConfig = {
  dimensions: 768,
  metric: 'cosine'
};

const col = sv.collection('embeddings', config);

Vector Operation Types

UpsertRecord

A vector record to insert or update.
interface UpsertRecord {
  id: string;
  values: number[];
  metadata?: Record<string, unknown>;
}
id
string
required
Unique identifier for the vector. Used for updates and retrieval.
values
number[]
required
Vector embedding values. Length must match collection dimensions.
metadata
Record<string, unknown>
Optional metadata object. Can contain any JSON-serializable values.

Example

const record: UpsertRecord = {
  id: 'doc_123',
  values: [0.1, 0.2, 0.3, ...],
  metadata: {
    text: 'The quick brown fox',
    source: 'document.pdf',
    page: 5,
    timestamp: Date.now(),
    tags: ['important', 'reviewed']
  }
};

await col.upsert([record]);

UpsertResponse

Response from an upsert operation.
interface UpsertResponse {
  upsertedCount: number;
}
upsertedCount
number
Number of vectors successfully upserted

Example

const response: UpsertResponse = await col.upsert(records);
console.log(`Inserted ${response.upsertedCount} vectors`);

QueryOptions

Options for querying nearest neighbors.
interface QueryOptions {
  vector: number[];
  topK: number;
  filter?: Record<string, unknown>;
  includeMetadata?: boolean;
  includeValues?: boolean;
}
vector
number[]
required
Query vector to find neighbors for. Must match collection dimensions.
topK
number
required
Number of nearest neighbors to return
filter
Record<string, unknown>
Metadata filters (not yet implemented)
includeMetadata
boolean
default:"true"
Whether to include metadata in results
includeValues
boolean
default:"false"
Whether to include vector values in results

Example

const options: QueryOptions = {
  vector: [0.1, 0.2, ...],
  topK: 10,
  includeMetadata: true,
  includeValues: false
};

const response = await col.query(options);

QueryMatch

A single matching vector from a query.
interface QueryMatch {
  id: string;
  score: number;
  metadata?: Record<string, unknown>;
  values?: number[];
}
id
string
Vector identifier
score
number
Similarity score. For cosine metric: 1.0 = identical, 0.0 = orthogonal, -1.0 = opposite.
metadata
Record<string, unknown>
Vector metadata (only present if includeMetadata: true)
values
number[]
Vector values (only present if includeValues: true)

Example

const { matches } = await col.query({ vector: [...], topK: 5 });

matches.forEach((match: QueryMatch) => {
  console.log(`ID: ${match.id}`);
  console.log(`Score: ${match.score.toFixed(4)}`);
  if (match.metadata) {
    console.log(`Text: ${match.metadata.text}`);
  }
});

QueryResponse

Complete response from a query operation.
interface QueryResponse {
  matches: QueryMatch[];
  namespace: string;
}
matches
QueryMatch[]
Array of matching vectors, sorted by similarity score (highest first)
namespace
string
Collection name that was queried

Example

const response: QueryResponse = await col.query({
  vector: [0.1, 0.2, ...],
  topK: 5
});

console.log(`Searched in: ${response.namespace}`);
console.log(`Found ${response.matches.length} matches`);

Collection Metadata Types

CollectionStats

Statistics and metadata about a collection.
interface CollectionStats {
  vectorCount: number;
  dimension: number;
  metric: DistanceMetric;
  name: string;
  merkleRoot: string;
  lastUpdated: number;
  isFrozen: boolean;
}
vectorCount
number
Total number of vectors in the collection
dimension
number
Vector dimensionality
metric
DistanceMetric
Distance metric used for similarity calculations
name
string
Collection name
merkleRoot
string
Current Merkle root hash (64-character hex string)
lastUpdated
number
Unix timestamp in milliseconds
isFrozen
boolean
Whether the collection is frozen (immutable)

Example

const stats: CollectionStats = await col.describeIndexStats();

console.log(`Collection: ${stats.name}`);
console.log(`Vectors: ${stats.vectorCount}`);
console.log(`Dimensions: ${stats.dimension}`);
console.log(`Metric: ${stats.metric}`);
console.log(`Merkle Root: ${stats.merkleRoot}`);
console.log(`Last Updated: ${new Date(stats.lastUpdated).toISOString()}`);
console.log(`Frozen: ${stats.isFrozen}`);

VerificationResult

Result of collection integrity verification.
interface VerificationResult {
  verified: boolean;
  onChainRoot: string;
  localRoot: string;
  match: boolean;
  vectorCount: number;
  solanaExplorerUrl: string;
  timestamp: number;
}
verified
boolean
Whether verification succeeded (true if roots match)
match
boolean
Whether local and on-chain Merkle roots match
localRoot
string
Locally computed Merkle root hash
onChainRoot
string
Merkle root stored on Solana blockchain
vectorCount
number
Number of vectors included in verification
solanaExplorerUrl
string
URL to view the collection on Solana Explorer
timestamp
number
Unix timestamp in milliseconds when verification was performed

Example

const result: VerificationResult = await col.verify();

if (result.verified && result.match) {
  console.log('✓ Collection integrity verified');
  console.log(`Verified ${result.vectorCount} vectors`);
  console.log(`View proof: ${result.solanaExplorerUrl}`);
} else {
  console.error('✗ Verification failed');
  console.error(`Local:    ${result.localRoot}`);
  console.error(`On-chain: ${result.onChainRoot}`);
}

Type Guards

You can create type guards for runtime type checking:
function isQueryMatch(obj: unknown): obj is QueryMatch {
  return (
    typeof obj === 'object' &&
    obj !== null &&
    'id' in obj &&
    'score' in obj &&
    typeof (obj as QueryMatch).id === 'string' &&
    typeof (obj as QueryMatch).score === 'number'
  );
}

function isValidNetwork(value: string): value is Network {
  return ['mainnet-beta', 'devnet', 'localnet'].includes(value);
}

Complete Type Reference

Import All Types

import type {
  // Configuration
  Network,
  DistanceMetric,
  SolVecConfig,
  CollectionConfig,
  
  // Vector Operations
  UpsertRecord,
  UpsertResponse,
  QueryOptions,
  QueryMatch,
  QueryResponse,
  
  // Metadata & Stats
  CollectionStats,
  VerificationResult
} from 'solvec';

Common Dimension Sizes

OpenAI

text-embedding-ada-002: 1536 dimensions

Sentence Transformers

all-mpnet-base-v2: 768 dimensionsall-MiniLM-L6-v2: 384 dimensions

Cohere

embed-english-v3.0: 1024 dimensions

Custom

Any dimension size supported

Build docs developers (and LLMs) love