Skip to main content

Overview

The SolVec class is the main entry point for interacting with VecLabs. It manages your connection to the Solana network and provides access to vector collections.

Constructor

import { SolVec } from 'solvec';

const sv = new SolVec(config);
config
SolVecConfig
required
Configuration object for the SolVec client

Example

// Connect to devnet with default RPC
const sv = new SolVec({ network: 'devnet' });

// Connect with wallet for write operations
const sv = new SolVec({
  network: 'mainnet-beta',
  walletPath: '/path/to/wallet.json'
});

// Use custom RPC endpoint
const sv = new SolVec({
  network: 'devnet',
  rpcUrl: 'https://my-custom-rpc.com'
});

Properties

connection
Connection
Solana web3.js Connection instance used for blockchain interactions
network
Network
The Solana network this client is connected to ("mainnet-beta", "devnet", or "localnet")
walletPublicKey
PublicKey | undefined
The connected wallet’s public key, if a wallet was provided during initialization

Methods

collection()

Get or create a vector collection. This is equivalent to Pinecone’s index() method.
const col = sv.collection(name, config?);
name
string
required
Unique name for the collection
config
CollectionConfig
Configuration for the collection
returns
SolVecCollection
A collection instance for performing vector operations

Example

// Create collection with default settings (1536 dimensions, cosine metric)
const col = sv.collection('agent-memory');

// Create collection with custom dimensions
const col = sv.collection('embeddings', { dimensions: 768 });

// Create collection with custom metric
const col = sv.collection('recommendations', {
  dimensions: 384,
  metric: 'euclidean'
});

listCollections()

List all collections owned by the connected wallet.
const collections = await sv.listCollections();
returns
Promise<string[]>
Array of collection names

Example

const sv = new SolVec({
  network: 'devnet',
  walletPath: './wallet.json'
});

const collections = await sv.listCollections();
console.log('My collections:', collections);
This method requires a wallet to be configured. It will throw an error if no wallet was provided during initialization.

Error Handling

try {
  const sv = new SolVec({ network: 'devnet' });
  const collections = await sv.listCollections();
} catch (error) {
  if (error.message.includes('Wallet required')) {
    console.error('Need to provide walletPath in config');
  }
}

Complete Example

import { SolVec } from 'solvec';

// Initialize client
const sv = new SolVec({
  network: 'devnet',
  walletPath: './wallet.json'
});

// Create a collection for OpenAI embeddings
const memory = sv.collection('agent-memory', {
  dimensions: 1536,
  metric: 'cosine'
});

// Store conversation context
await memory.upsert([
  {
    id: 'mem_001',
    values: [...], // 1536-dim embedding
    metadata: { text: 'User is Alex', timestamp: Date.now() }
  }
]);

// Query for relevant memories
const { matches } = await memory.query({
  vector: [...], // query embedding
  topK: 5
});

console.log('Relevant memories:', matches);

Type Reference

See the Types documentation for detailed type definitions.

Build docs developers (and LLMs) love