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 );
Configuration object for the SolVec client Solana network to connect to: "mainnet-beta", "devnet", or "localnet"
Path to Solana wallet keypair JSON file. Required for write operations and listing collections.
Custom RPC endpoint URL. If not provided, uses default URLs:
mainnet-beta: https://api.mainnet-beta.solana.com
devnet: https://api.devnet.solana.com
localnet: http://localhost:8899
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
Solana web3.js Connection instance used for blockchain interactions
The Solana network this client is connected to ("mainnet-beta", "devnet", or "localnet")
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 ? );
Unique name for the collection
Configuration for the collection Vector dimensionality (e.g., 1536 for OpenAI embeddings, 768 for sentence-transformers)
metric
DistanceMetric
default: "cosine"
Distance metric: "cosine", "euclidean", or "dot"
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 ();
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.