Memory Provider

The Memory provider is an in-memory vector store built into Vectra. It is designed exclusively for testing, local development, and CI – no external database required.

Not for production use. All data lives in process memory and is lost when the process exits.

When to Use

Setup

Global Configuration (Rails Example)

# config/initializers/vectra.rb
Vectra.configure do |config|
  config.provider = :memory if Rails.env.test?
end

Then in your application code:

client = Vectra::Client.new

Direct Construction

require "vectra"

client = Vectra.memory

No host, api_key, or environment configuration is required.

Features

Basic Usage

client = Vectra.memory

# Upsert
client.upsert(
  index: "documents",
  vectors: [
    {
      id: "doc-1",
      values: [0.1, 0.2, 0.3],
      metadata: { title: "Hello", category: "docs" }
    }
  ],
  namespace: "test-suite"
)

# Query
results = client.query(
  index: "documents",
  vector: [0.1, 0.2, 0.3],
  top_k: 5,
  namespace: "test-suite",
  filter: { category: "docs" },
  include_metadata: true
)

results.each do |match|
  puts "#{match.id}: #{match.metadata["title"]} (score=#{match.score.round(3)})"
end

Metadata Filtering

The Memory provider supports a subset of the same filter operators as other providers:

results = client.query(
  index: "products",
  vector: query_embedding,
  top_k: 10,
  filter: {
    status: ["active", "preview"],         # IN
    price: { "$gte" => 10, "$lte" => 100 },# range
    brand: { "$ne" => "Acme" }             # not equal
  },
  include_metadata: true
)

Supported operators:

Resetting State Between Tests

The Memory provider exposes a clear! method to reset all in-memory state:

RSpec.describe "MyService" do
  let(:client) { Vectra.memory }

  before do
    client.provider.clear! if client.provider.respond_to?(:clear!)
  end

  # your tests...
end

You can also call clear! on the provider obtained from a regular Vectra::Client:

client = Vectra::Client.new(provider: :memory)
client.provider.clear!

Limitations