Vectorstore

Persist embeddings and search by similarity.

What it is

A vector store is where you persist embedding vectors so you can query them later with nearest-neighbor similarity search. In a RAG system, it’s the component that lets you retrieve relevant chunks or memories for a new question.

In Phero, vector stores are typically used through the rag package: you ingest chunks (embed + store), then query by embedding the user’s question.

How it fits in the stack

Example: Qdrant-backed store (document RAG)

The examples/rag-chatbot program uses Qdrant. The important parts are:

// From examples/rag-chatbot (edited for brevity)

// Infer vector size from the embedder output
vecs, err := embedder.Embed(ctx, []string{chunks[0]})
if err != nil {
    // handle error
}
vectorSize := uint64(len(vecs[0]))

// Qdrant client
qc, err := qdrantapi.NewClient(&qdrantapi.Config{
    Host:   qdrantHost,
    Port:   qdrantPort,
    APIKey: strings.TrimSpace(qdrantAPIKey),
    UseTLS: qdrantUseTLS,
})
if err != nil {
    // handle error
}

// Vector store bound to a single collection
store, err := vsqdrant.New(
    qc,
    strings.TrimSpace(qdrantCollection),
    vsqdrant.WithVectorSize(vectorSize),
    vsqdrant.WithWait(true),
)
if err != nil {
    // handle error
}

// Use the store via RAG
ragEngine, _ := rag.New(store, embedder, rag.WithTopK(topK))

The RAG engine handles ingestion and retrieval; the vector store’s job is to provide durable storage and fast similarity search.

Example: Qdrant-backed store (semantic memory)

The examples/long-term-memory program uses the same Qdrant store, but wraps the RAG engine as semantic memory.

// From examples/long-term-memory (edited for brevity)

store, err := vsqdrant.New(
    qc,
    qdrantCollection,
    vsqdrant.WithVectorSize(vectorSize),
    vsqdrant.WithWait(true),
)
if err != nil {
    // handle error
}

// Ensure the collection exists
_ = store.EnsureCollection(ctx)

ragEngine, _ := rag.New(store, embedder, rag.WithTopK(topK))
conversationMemory := ragmemory.New(ragEngine)

a.SetMemory(conversationMemory)

Run the examples

The Qdrant-based examples require a running Qdrant instance. Provider setup depends on your chosen LLM/embedder; follow each example README.

# Start Qdrant (one quick way)
docker run --rm -p 6333:6333 -p 6334:6334 qdrant/qdrant

# Document RAG over a local file

go run ./examples/rag-chatbot -file /path/to/your/file.txt

# Semantic long-term memory

go run ./examples/long-term-memory

Other backends

Phero includes a PostgreSQL + pgvector adapter under vectorstore/psql and a Weaviate adapter under vectorstore/weaviate.

PostgreSQL (pgvector)

Use it when you want vectors stored alongside your relational data. The store is bound to a logical collection name, but (by default) stores all collections in a single table named vector_store with a collection column.

import (
    "database/sql"
    "os"

    _ "github.com/jackc/pgx/v5/stdlib"

    vspql "github.com/henomis/phero/vectorstore/psql"
)

db, err := sql.Open("pgx", os.Getenv("DATABASE_URL"))
if err != nil {
    // handle error
}

store, err := vspql.New(db, "my_collection", vspql.WithVectorSize(1536))
if err != nil {
    // handle error
}

_ = store.EnsureCollection(ctx)

The PostgreSQL adapter also lets you pick the distance metric with vspql.WithDistance(...), disable automatic extension setup with vspql.WithEnsureExtension(false), and override the backing table with vspql.WithTable("...").

Weaviate

Use when you have an existing Weaviate instance. Inject an already-configured *weaviate.Client and pick your distance metric.

import (
    weaviateclient "github.com/weaviate/weaviate-go-client/v4/weaviate"

    vsweaviate "github.com/henomis/phero/vectorstore/weaviate"
)

c := weaviateclient.New(weaviateclient.Config{
    Host:   "localhost:8080",
    Scheme: "http",
})

store, err := vsweaviate.New(
    c,
    "MyCollection",
    vsweaviate.WithVectorSize(1536),
    vsweaviate.WithDistance(vsweaviate.DistanceCosine), // default
    vsweaviate.WithBatchSize(50),
)
if err != nil {
    // handle error
}

_ = store.EnsureCollection(ctx)

Supported distance metrics: DistanceCosine (default), DistanceDot, DistanceL2.

Related packages