Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing Sequel connection options #842

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/langchain/vectorsearch/pgvector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class Pgvector < Base
# @param index_name [String] The name of the table to use for the index
# @param llm [Object] The LLM client to use
# @param namespace [String] The namespace to use for the index when inserting/querying
def initialize(url:, index_name:, llm:, namespace: nil)
def initialize(url:, index_name:, llm:, namespace: nil, connection_options: {})
depends_on "sequel"
depends_on "pgvector"

@db = Sequel.connect(url)
@db = Sequel.connect(url, connection_options)

@table_name = index_name

Expand All @@ -57,7 +57,6 @@ def upsert_texts(texts:, ids:)
data = texts.zip(ids).flat_map do |(text, id)|
{id: id, content: text, vectors: llm.embed(text: text).embedding.to_s, namespace: namespace}
end
# @db[table_name.to_sym].multi_insert(data, return: :primary_key)
@db[table_name.to_sym]
.insert_conflict(
target: :id,
Expand Down
17 changes: 17 additions & 0 deletions spec/langchain/vectorsearch/pgvector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,5 +255,22 @@
end
end
end

describe "#initialize" do
context "with connection options" do
it "creates a new instance with connection options passed to the db" do
custom_pgvector = Langchain::Vectorsearch::Pgvector.new(
url: ENV["POSTGRES_URL"],
index_name: "products",
llm: Langchain::LLM::OpenAI.new(api_key: "123"),
connection_options: {
max_connections: 10
}
)

expect(custom_pgvector.db.opts[:max_connections]).to eq(10)
end
end
end
end
end