langchainrb 0.6.12 → 0.6.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4567e8a572ad802d06af2571fd5be51a0376a7507f74474eb0598198b5cc29a
4
- data.tar.gz: 1032626da89febc17cbf76db2f37a17fbfe53398291cd8fa6e3726d621b9f429
3
+ metadata.gz: 9a8dc8c16a235328e6122725804fc8dface37910d2014ecf44410631d3ec63cb
4
+ data.tar.gz: 5d69e6b1dda419d2834f9041a18eae48b2c63303cc901515cd883153635f0742
5
5
  SHA512:
6
- metadata.gz: 1119378271d50091473d3999c16c78479da6fe7609e1583d3a2f964e7edc1f4802ee98646e4a22d784cd600cdbfdff2da9313ca492f77d2f2743a6ae6082f9bd
7
- data.tar.gz: c85e6f0b76bb982546531cc9a2403c4bb9de60b9270078739c1591a563ab6e5404bb94177cef7281e9cbfdfb2938386f3bbdfdd182d202d3bedabef2dfd1383c
6
+ metadata.gz: 0c176e717986c0bb0b74761858bf0a6aac8e84fff179791fd67b68441760d5a419ae767bb678bab8a783bfaf6a17f53b7177b24d96fd8f1b076fd4f091c5443e
7
+ data.tar.gz: a0457aaf411f8932ada4bb3683fef81396334186047a5bb26040c0c03634443662806ad3d2d37ec81f4121f519e387f77688e395cc38882b7f8ab85c0795fba6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.6.13] - 2023-08-23
4
+ - Add `k:` parameter to all `ask()` vector search methods
5
+ - Bump Faraday to 2.x
6
+
3
7
  ## [0.6.12] - 2023-08-13
4
8
 
5
9
  ## [0.6.11] - 2023-08-08
data/README.md CHANGED
@@ -61,10 +61,10 @@ client = Langchain::Vectorsearch::Weaviate.new(
61
61
  # You can instantiate any other supported vector search database:
62
62
  client = Langchain::Vectorsearch::Chroma.new(...) # `gem "chroma-db", "~> 0.3.0"`
63
63
  client = Langchain::Vectorsearch::Hnswlib.new(...) # `gem "hnswlib", "~> 0.8.1"`
64
- client = Langchain::Vectorsearch::Milvus.new(...) # `gem "milvus", "~> 0.9.0"`
64
+ client = Langchain::Vectorsearch::Milvus.new(...) # `gem "milvus", "~> 0.9.2"`
65
65
  client = Langchain::Vectorsearch::Pinecone.new(...) # `gem "pinecone", "~> 0.1.6"`
66
66
  client = Langchain::Vectorsearch::Pgvector.new(...) # `gem "pgvector", "~> 0.2"`
67
- client = Langchain::Vectorsearch::Qdrant.new(...) # `gem"qdrant-ruby", "~> 0.9.0"`
67
+ client = Langchain::Vectorsearch::Qdrant.new(...) # `gem"qdrant-ruby", "~> 0.9.3"`
68
68
  ```
69
69
 
70
70
  ```ruby
@@ -164,7 +164,7 @@ client.llm.functions = functions
164
164
  ```
165
165
 
166
166
  #### Cohere
167
- Add `gem "cohere-ruby", "~> 0.9.3"` to your Gemfile.
167
+ Add `gem "cohere-ruby", "~> 0.9.6"` to your Gemfile.
168
168
 
169
169
  ```ruby
170
170
  cohere = Langchain::LLM::Cohere.new(api_key: ENV["COHERE_API_KEY"])
@@ -189,7 +189,7 @@ replicate = Langchain::LLM::Replicate.new(api_key: ENV["REPLICATE_API_KEY"])
189
189
  ```
190
190
 
191
191
  #### Google PaLM (Pathways Language Model)
192
- Add `"google_palm_api", "~> 0.1.2"` to your Gemfile.
192
+ Add `"google_palm_api", "~> 0.1.3"` to your Gemfile.
193
193
  ```ruby
194
194
  google_palm = Langchain::LLM::GooglePalm.new(api_key: ENV["GOOGLE_PALM_API_KEY"])
195
195
  ```
@@ -5,7 +5,7 @@ module Langchain::LLM
5
5
  # Wrapper around the Cohere API.
6
6
  #
7
7
  # Gem requirements:
8
- # gem "cohere-ruby", "~> 0.9.5"
8
+ # gem "cohere-ruby", "~> 0.9.6"
9
9
  #
10
10
  # Usage:
11
11
  # cohere = Langchain::LLM::Cohere.new(api_key: "YOUR_API_KEY")
@@ -5,7 +5,7 @@ module Langchain::LLM
5
5
  # Wrapper around the Google PaLM (Pathways Language Model) APIs: https://ai.google/build/machine-learning/
6
6
  #
7
7
  # Gem requirements:
8
- # gem "google_palm_api", "~> 0.1.2"
8
+ # gem "google_palm_api", "~> 0.1.3"
9
9
  #
10
10
  # Usage:
11
11
  # google_palm = Langchain::LLM::GooglePalm.new(api_key: "YOUR_API_KEY")
@@ -98,8 +98,8 @@ module Langchain
98
98
  Dir.glob(File.join(@path, "**/*")).map do |file|
99
99
  # Only load and add to result files with supported extensions
100
100
  Langchain::Loader.new(file, @options).load(&block)
101
- rescue
102
- UnknownFormatError nil
101
+ rescue => e
102
+ UnknownFormatError.new(e)
103
103
  end.flatten.compact
104
104
  end
105
105
 
@@ -134,6 +134,7 @@ module Langchain
134
134
  end
135
135
 
136
136
  def source_type
137
+ binding.pry
137
138
  url? ? @raw_data.content_type : File.extname(@path)
138
139
  end
139
140
 
@@ -113,10 +113,11 @@ module Langchain::Vectorsearch
113
113
 
114
114
  # Ask a question and return the answer
115
115
  # @param question [String] The question to ask
116
+ # @param k [Integer] The number of results to have in context
116
117
  # @yield [String] Stream responses back one String at a time
117
118
  # @return [String] The answer to the question
118
- def ask(question:, &block)
119
- search_results = similarity_search(query: question)
119
+ def ask(question:, k: 4, &block)
120
+ search_results = similarity_search(query: question, k: k)
120
121
 
121
122
  context = search_results.map do |result|
122
123
  result.document
@@ -5,7 +5,7 @@ module Langchain::Vectorsearch
5
5
  #
6
6
  # Wrapper around Milvus REST APIs.
7
7
  #
8
- # Gem requirements: gem "milvus", "~> 0.9.0"
8
+ # Gem requirements: gem "milvus", "~> 0.9.2"
9
9
  #
10
10
  # Usage:
11
11
  # milvus = Langchain::Vectorsearch::Milvus.new(url:, index_name:, llm:, api_key:)
@@ -138,10 +138,11 @@ module Langchain::Vectorsearch
138
138
 
139
139
  # Ask a question and return the answer
140
140
  # @param question [String] The question to ask
141
+ # @param k [Integer] The number of results to have in context
141
142
  # @yield [String] Stream responses back one String at a time
142
143
  # @return [String] The answer to the question
143
- def ask(question:, &block)
144
- search_results = similarity_search(query: question)
144
+ def ask(question:, k: 4, &block)
145
+ search_results = similarity_search(query: question, k: k)
145
146
 
146
147
  content_field = search_results.dig("results", "fields_data").select { |field| field.dig("field_name") == "content" }
147
148
  content_data = content_field.first.dig("Field", "Scalars", "Data", "StringData", "data")
@@ -135,10 +135,11 @@ module Langchain::Vectorsearch
135
135
 
136
136
  # Ask a question and return the answer
137
137
  # @param question [String] The question to ask
138
+ # @param k [Integer] The number of results to have in context
138
139
  # @yield [String] Stream responses back one String at a time
139
140
  # @return [String] The answer to the question
140
- def ask(question:, &block)
141
- search_results = similarity_search(query: question)
141
+ def ask(question:, k: 4, &block)
142
+ search_results = similarity_search(query: question, k: k)
142
143
 
143
144
  context = search_results.map do |result|
144
145
  result.content.to_s
@@ -51,6 +51,21 @@ module Langchain::Vectorsearch
51
51
  index.upsert(vectors: vectors, namespace: namespace)
52
52
  end
53
53
 
54
+ def add_data(paths:, namespace: "")
55
+ raise ArgumentError, "Paths must be provided" if Array(paths).empty?
56
+
57
+ texts = Array(paths)
58
+ .flatten
59
+ .map do |path|
60
+ data = Langchain::Loader.new(path)&.load&.chunks
61
+ data.map { |chunk| chunk[:text] }
62
+ end
63
+
64
+ texts.flatten!
65
+
66
+ add_texts(texts: texts, namespace: namespace)
67
+ end
68
+
54
69
  # Update a list of texts in the index
55
70
  # @param texts [Array] The list of texts to update
56
71
  # @param ids [Array] The list of IDs to update
@@ -138,11 +153,12 @@ module Langchain::Vectorsearch
138
153
  # Ask a question and return the answer
139
154
  # @param question [String] The question to ask
140
155
  # @param namespace [String] The namespace to search in
156
+ # @param k [Integer] The number of results to have in context
141
157
  # @param filter [String] The filter to use
142
158
  # @yield [String] Stream responses back one String at a time
143
159
  # @return [String] The answer to the question
144
- def ask(question:, namespace: "", filter: nil, &block)
145
- search_results = similarity_search(query: question, namespace: namespace, filter: filter)
160
+ def ask(question:, namespace: "", filter: nil, k: 4, &block)
161
+ search_results = similarity_search(query: question, namespace: namespace, filter: filter, k: k)
146
162
 
147
163
  context = search_results.map do |result|
148
164
  result.dig("metadata").to_s
@@ -5,7 +5,7 @@ module Langchain::Vectorsearch
5
5
  #
6
6
  # Wrapper around Qdrant
7
7
  #
8
- # Gem requirements: gem "qdrant-ruby", "~> 0.9.0"
8
+ # Gem requirements: gem "qdrant-ruby", "~> 0.9.3"
9
9
  #
10
10
  # Usage:
11
11
  # qdrant = Langchain::Vectorsearch::Qdrant.new(url:, api_key:, index_name:, llm:, llm_api_key:)
@@ -112,10 +112,11 @@ module Langchain::Vectorsearch
112
112
 
113
113
  # Ask a question and return the answer
114
114
  # @param question [String] The question to ask
115
+ # @param k [Integer] The number of results to have in context
115
116
  # @yield [String] Stream responses back one String at a time
116
117
  # @return [String] The answer to the question
117
- def ask(question:, &block)
118
- search_results = similarity_search(query: question)
118
+ def ask(question:, k: 4, &block)
119
+ search_results = similarity_search(query: question, k: k)
119
120
 
120
121
  context = search_results.map do |result|
121
122
  result.dig("payload").to_s
@@ -124,10 +124,11 @@ module Langchain::Vectorsearch
124
124
 
125
125
  # Ask a question and return the answer
126
126
  # @param question [String] The question to ask
127
+ # @param k [Integer] The number of results to have in context
127
128
  # @yield [String] Stream responses back one String at a time
128
129
  # @return [Hash] The answer
129
- def ask(question:, &block)
130
- search_results = similarity_search(query: question)
130
+ def ask(question:, k: 4, &block)
131
+ search_results = similarity_search(query: question, k: k)
131
132
 
132
133
  context = search_results.map do |result|
133
134
  result.dig("content").to_s
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Langchain
4
- VERSION = "0.6.12"
4
+ VERSION = "0.6.13"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: langchainrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.12
4
+ version: 0.6.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Bondarev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-13 00:00:00.000000000 Z
11
+ date: 2023-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: baran
@@ -184,14 +184,14 @@ dependencies:
184
184
  requirements:
185
185
  - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: 0.9.5
187
+ version: 0.9.6
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
- version: 0.9.5
194
+ version: 0.9.6
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: docx
197
197
  requirement: !ruby/object:Gem::Requirement
@@ -226,14 +226,14 @@ dependencies:
226
226
  requirements:
227
227
  - - "~>"
228
228
  - !ruby/object:Gem::Version
229
- version: 0.1.2
229
+ version: 0.1.3
230
230
  type: :development
231
231
  prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
234
  - - "~>"
235
235
  - !ruby/object:Gem::Version
236
- version: 0.1.2
236
+ version: 0.1.3
237
237
  - !ruby/object:Gem::Dependency
238
238
  name: google_search_results
239
239
  requirement: !ruby/object:Gem::Requirement
@@ -282,14 +282,14 @@ dependencies:
282
282
  requirements:
283
283
  - - "~>"
284
284
  - !ruby/object:Gem::Version
285
- version: 0.9.0
285
+ version: 0.9.2
286
286
  type: :development
287
287
  prerelease: false
288
288
  version_requirements: !ruby/object:Gem::Requirement
289
289
  requirements:
290
290
  - - "~>"
291
291
  - !ruby/object:Gem::Version
292
- version: 0.9.0
292
+ version: 0.9.2
293
293
  - !ruby/object:Gem::Dependency
294
294
  name: llama_cpp
295
295
  requirement: !ruby/object:Gem::Requirement
@@ -324,14 +324,14 @@ dependencies:
324
324
  requirements:
325
325
  - - "~>"
326
326
  - !ruby/object:Gem::Version
327
- version: 0.3.0
327
+ version: 0.4.0
328
328
  type: :development
329
329
  prerelease: false
330
330
  version_requirements: !ruby/object:Gem::Requirement
331
331
  requirements:
332
332
  - - "~>"
333
333
  - !ruby/object:Gem::Version
334
- version: 0.3.0
334
+ version: 0.4.0
335
335
  - !ruby/object:Gem::Dependency
336
336
  name: pg
337
337
  requirement: !ruby/object:Gem::Requirement
@@ -408,14 +408,14 @@ dependencies:
408
408
  requirements:
409
409
  - - "~>"
410
410
  - !ruby/object:Gem::Version
411
- version: 0.9.0
411
+ version: 0.9.3
412
412
  type: :development
413
413
  prerelease: false
414
414
  version_requirements: !ruby/object:Gem::Requirement
415
415
  requirements:
416
416
  - - "~>"
417
417
  - !ruby/object:Gem::Version
418
- version: 0.9.0
418
+ version: 0.9.3
419
419
  - !ruby/object:Gem::Dependency
420
420
  name: roo
421
421
  requirement: !ruby/object:Gem::Requirement
@@ -478,14 +478,14 @@ dependencies:
478
478
  requirements:
479
479
  - - "~>"
480
480
  - !ruby/object:Gem::Version
481
- version: 0.8.3
481
+ version: 0.8.6
482
482
  type: :development
483
483
  prerelease: false
484
484
  version_requirements: !ruby/object:Gem::Requirement
485
485
  requirements:
486
486
  - - "~>"
487
487
  - !ruby/object:Gem::Version
488
- version: 0.8.3
488
+ version: 0.8.6
489
489
  - !ruby/object:Gem::Dependency
490
490
  name: wikipedia-client
491
491
  requirement: !ruby/object:Gem::Requirement