Rag.VectorStore.Store behaviour (rag v0.3.4)
View SourceBehaviour for vector store backends.
This behaviour defines the interface for different vector storage implementations (pgvector, Pinecone, Qdrant, etc.).
Implementing a Custom Store
defmodule MyApp.CustomVectorStore do
@behaviour Rag.VectorStore.Store
defstruct [:connection]
@impl true
def insert(store, documents, opts) do
# Insert documents with embeddings
{:ok, count}
end
@impl true
def search(store, embedding, opts) do
# Search by embedding similarity
{:ok, results}
end
@impl true
def delete(store, ids, opts) do
# Delete by IDs
{:ok, count}
end
@impl true
def get(store, ids, opts) do
# Get by IDs
{:ok, documents}
end
endAvailable Implementations
Rag.VectorStore.Pgvector- PostgreSQL with pgvector extension
Summary
Callbacks
Delete documents by IDs.
Get documents by IDs.
Insert documents with embeddings into the store.
Search for similar documents by embedding.
Functions
Delete documents from the store.
Get documents from the store by IDs.
Insert documents into the store.
Search the store by embedding.
Types
Callbacks
@callback delete(store :: struct(), ids :: [any()], opts :: keyword()) :: {:ok, non_neg_integer()} | {:error, term()}
Delete documents by IDs.
Parameters
store- The store structids- List of document IDs to deleteopts- Options specific to the implementation
Returns
{:ok, count}- Number of documents deleted{:error, reason}- Error during deletion
@callback get(store :: struct(), ids :: [any()], opts :: keyword()) :: {:ok, [document()]} | {:error, term()}
Get documents by IDs.
Parameters
store- The store structids- List of document IDs to retrieveopts- Options specific to the implementation
Returns
{:ok, [document]}- List of documents{:error, reason}- Error during retrieval
@callback insert(store :: struct(), documents :: [document()], opts :: keyword()) :: {:ok, non_neg_integer()} | {:error, term()}
Insert documents with embeddings into the store.
Parameters
store- The store structdocuments- List of documents with embeddingsopts- Options specific to the implementation
Returns
{:ok, count}- Number of documents inserted{:error, reason}- Error during insertion
@callback search(store :: struct(), embedding :: embedding(), opts :: keyword()) :: {:ok, [result()]} | {:error, term()}
Search for similar documents by embedding.
Parameters
store- The store structembedding- Query embedding vectoropts- Options including:limit
Returns
{:ok, [result]}- List of results with similarity scores{:error, reason}- Error during search
Functions
@spec delete(struct(), [any()], keyword()) :: {:ok, non_neg_integer()} | {:error, term()}
Delete documents from the store.
Get documents from the store by IDs.
@spec insert(struct(), [document()], keyword()) :: {:ok, non_neg_integer()} | {:error, term()}
Insert documents into the store.
Search the store by embedding.