Class: Boxcars::VectorStore::Pgvector::Search

Inherits:
Object
  • Object
show all
Includes:
Boxcars::VectorStore
Defined in:
lib/boxcars/vector_store/pgvector/search.rb

Instance Method Summary collapse

Methods included from Boxcars::VectorStore

included

Constructor Details

#initialize(params) ⇒ Search

initialize the vector store with the following parameters: example: {

type: :pgvector,
vector_store: {
  table_name: "vector_store",
  embedding_column_name: "embedding",
  content_column_name: "content",
  database_url: ENV['DATABASE_URL']
}

}

Parameters:

  • params (Hash)

    A Hash containing the initial configuration.

Options Hash (params):

  • :vector_documents (Hash)

    The vector documents to search.

  • :vector_store (Hash)

    The vector store to search.



27
28
29
30
31
32
33
# File 'lib/boxcars/vector_store/pgvector/search.rb', line 27

def initialize(params)
  vector_store = validate_params(params)
  db_url = validate_vector_store(vector_store)
  @db_connection = test_db(db_url)

  @vector_documents = params[:vector_documents]
end

Instance Method Details

#call(query_vector:, count: 1) ⇒ Array

Returns array of hashes with :document and :distance keys.

Examples:

[
  {
    document: Boxcars::VectorStore::Document.new(
      content: "hello",
      embedding: [0.1, 0.2, 0.3],
      metadata: { a: 1 }
    ),
    distance: 0.1
  }
]

Parameters:

  • query_vector (Array)

    The query vector to search for.

  • count (Integer) (defaults to: 1)

    The number of results to return.

Returns:

  • (Array)

    array of hashes with :document and :distance keys

Raises:



49
50
51
52
53
# File 'lib/boxcars/vector_store/pgvector/search.rb', line 49

def call(query_vector:, count: 1)
  raise ::Boxcars::ArgumentError, 'query_vector is empty' if query_vector.empty?

  search(query_vector, count)
end