Skip to content

Commit c261d32

Browse files
enhancements
1 parent fa928d7 commit c261d32

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

lib/langchainrb_overrides/vectorsearch/pgvector.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# frozen_string_literal: true
22

3+
# Overriding Langchain.rb's Pgvector implementation to use ActiveRecord.
4+
# Original implementation: https://github.com/andreibondarev/langchainrb/blob/main/lib/langchain/vectorsearch/pgvector.rb
5+
36
module Langchain::Vectorsearch
47
class Pgvector < Base
58
#
@@ -20,7 +23,7 @@ class Pgvector < Base
2023
]
2124
DEFAULT_OPERATOR = "cosine"
2225

23-
attr_reader :db, :operator, :llm
26+
attr_reader :operator, :llm
2427
attr_accessor :model
2528

2629
# @param url [String] The URL of the PostgreSQL database
@@ -119,7 +122,3 @@ def ask(question, k: 4, &block)
119122
end
120123
end
121124
end
122-
123-
# Rails connection when configuring vectorsearch
124-
# Update READMEs
125-
# Rails migration to create a migration
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe Langchain::Vectorsearch::Pgvector do
4+
let(:llm) { Langchain::LLM::OpenAI.new(api_key: "123") }
5+
subject { described_class.new(llm: llm) }
6+
7+
describe "#add_texts" do
8+
end
9+
10+
describe "#update_text" do
11+
end
12+
13+
describe "#create_default_schema" do
14+
end
15+
16+
describe "#destroy_default_schema" do
17+
end
18+
19+
describe "#similarity_search" do
20+
end
21+
22+
describe "#similarity_search_by_vector" do
23+
end
24+
25+
describe "#ask" do
26+
end
27+
end

spec/langchainrb_rails/active_record/hooks_spec.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ class Dummy
1010
expect(::Dummy.new).to respond_to(:as_vector)
1111
end
1212

13-
it "responds to class method: similarity_search" do
13+
it "responds to class methods" do
1414
expect(::Dummy).to respond_to(:vectorsearch)
1515
expect(::Dummy).to respond_to(:similarity_search)
16-
end
17-
18-
it "responds to class method: ask" do
19-
expect(::Dummy).to respond_to(:vectorsearch)
2016
expect(::Dummy).to respond_to(:ask)
17+
expect(::Dummy).to respond_to(:embed!)
2118
end
2219
end

0 commit comments

Comments
 (0)