Skip to main content

Overview

The SolVec class is the main entry point for the VecLabs Python SDK. It manages connections to the Solana network and provides access to vector collections.

Constructor

from solvec import SolVec

sv = SolVec(
    network="devnet",
    wallet="~/.config/solana/id.json",
    rpc_url=None
)

Parameters

network
str
default:"devnet"
Solana network to connect to. Options:
  • "mainnet-beta" - Production Solana mainnet
  • "devnet" - Solana devnet for testing
  • "localnet" - Local Solana validator
wallet
str | None
default:"None"
Path to your Solana keypair JSON file. Required for write operations (upsert, delete).Example: "~/.config/solana/id.json"
rpc_url
str | None
default:"None"
Custom RPC URL. If not provided, uses default RPC for the selected network.Use this for premium RPC providers like Helius or QuickNode for better performance.

Raises

  • ValueError - If an invalid network name is provided

Methods

collection()

Get or create a vector collection. Equivalent to Pinecone’s Index().
col = sv.collection(
    name="agent-memory",
    dimensions=1536,
    metric="cosine"
)

Parameters

name
str
required
Collection name (maximum 64 characters). Used as a unique identifier for the collection.
dimensions
int
default:"1536"
Vector dimension. Default is 1536, which matches OpenAI’s text-embedding-3-small and text-embedding-ada-002 models.Common dimensions:
  • 1536 - OpenAI embeddings
  • 768 - Sentence transformers
  • 384 - MiniLM models
metric
str | DistanceMetric
default:"DistanceMetric.COSINE"
Distance metric for similarity search. Options:
  • "cosine" or DistanceMetric.COSINE - Cosine similarity (recommended for most use cases)
  • "euclidean" or DistanceMetric.EUCLIDEAN - Euclidean distance
  • "dot" or DistanceMetric.DOT - Dot product

Returns

collection
SolVecCollection
A SolVecCollection instance for performing vector operations.

Example

from solvec import SolVec

sv = SolVec(network="devnet", wallet="~/.config/solana/id.json")

# Create collection for OpenAI embeddings
col = sv.collection("agent-memory", dimensions=1536)

# Create collection with Euclidean distance
col = sv.collection(
    "image-vectors",
    dimensions=768,
    metric="euclidean"
)

list_collections()

List all collection names in the current session.
collections = sv.list_collections()

Returns

collections
list[str]
List of collection names that have been accessed in this session.

Example

sv = SolVec(network="devnet")

col1 = sv.collection("memories")
col2 = sv.collection("facts")

print(sv.list_collections())  # Output: ['memories', 'facts']

Class Attributes

RPC_URLS

Default RPC URLs for each Solana network:
RPC_URLS = {
    "mainnet-beta": "https://api.mainnet-beta.solana.com",
    "devnet": "https://api.devnet.solana.com",
    "localnet": "http://localhost:8899",
}

Complete Example

from solvec import SolVec
import openai

# Initialize SolVec client
sv = SolVec(
    network="devnet",
    wallet="~/.config/solana/id.json"
)

# Get or create a collection
col = sv.collection("agent-memory", dimensions=1536)

# Generate embeddings with OpenAI
text = "User prefers dark mode"
response = openai.embeddings.create(
    model="text-embedding-3-small",
    input=text
)
embedding = response.data[0].embedding

# Store vector
col.upsert([{
    "id": "mem_001",
    "values": embedding,
    "metadata": {"text": text, "category": "preference"}
}])

# Query for similar memories
results = col.query(vector=embedding, top_k=5)
for match in results.matches:
    print(f"{match.id}: {match.metadata['text']} (score: {match.score})")

Notes

  • Collections are cached in memory per SolVec instance
  • Calling collection() multiple times with the same name returns the same instance
  • The SDK is designed to be Pinecone-compatible for easy migration

Build docs developers (and LLMs) love