bx_builder_chain 0.1.16 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aad98d1bac1b55ae34b9f092ca2e1611a3358c69a10b3b3b5af552f2619589ea
4
- data.tar.gz: 32f1d91df4c276ad118adc687ea272f5dac5760ec04ad3d2970607f348abdd5c
3
+ metadata.gz: 022f97be7d06eac31ca9d9f70f541b9fc3636ae44f7fda16ee72f43e5b86aa69
4
+ data.tar.gz: dbe3501ebd87e3e3f1149b31e66a35bd26649c60c06e5195d87ba98a7c7c7913
5
5
  SHA512:
6
- metadata.gz: 8c6ade2b2818b871b89bb770438d43c67a6889522ae00d7ff4c30b58b3f92adf66874e7966b842325a4b6d5a7e311560d5fdc4d7496b4ab96caa0c09314e1093
7
- data.tar.gz: 4ad5f52faa63cb00f1bd3decd42ac176bf931cef497857e77d505224edd5d4dc44d48db0b5b6a9ddefb84f53a220a6239726982eaaef98752c7a2e8469f08763
6
+ metadata.gz: c10fbc01e9cedfa8ffb188e3d47c3522c931830002099a71b623b31574af2fb0b3df089760593d3b7e87fb38a1257eef54c4fde0b32eb600adea8dabdc234471
7
+ data.tar.gz: 95b0b54b0fbeba57225f6d7a07f2166dc3b28b4ea0a973d08cecdff7e3f870030f470df662a329dcc4b364b7c346e9357f9acfd693e67307e2c8cd05db4d8a92
@@ -69,21 +69,26 @@ module BxBuilderChain::Vectorsearch
69
69
  # @return [Array<Integer>] The the ids of the added texts.
70
70
  def add_texts(texts:, ids: nil)
71
71
  if ids.nil? || ids.empty?
72
- Async do |parent|
73
- data = texts.each_slice(20).flat_map do |text_batch| # Process in batches of 20
72
+ mutex = Mutex.new
73
+ texts.each_slice(10).flat_map do |text_batch| # Process in batches of 10
74
+ data = []
75
+ Async do |parent|
74
76
  text_batch.map do |text|
75
77
  parent.async do |task|
76
78
  begin
77
- {content: text, vectors: llm.embed(text: text).to_s, namespace: namespaces[0]}
79
+ vectorised_text = {content: text, vectors: llm.embed(text: text).to_s, namespace: namespaces[0]}
80
+ mutex.synchronize do
81
+ data << vectorised_text
82
+ end
78
83
  rescue => e
79
84
  puts "Error processing text: #{e.message}"
80
85
  nil # or some error indication
81
86
  end
82
87
  end
83
- end.map(&:wait) # Ensure all tasks in the batch are completed
84
- end
88
+ end # Ensure all tasks in the batch are completed
89
+ end.map(&:wait)
90
+ @db[@table_name.to_sym].multi_insert(data, return: :primary_key)
85
91
  end
86
- @db[@table_name.to_sym].multi_insert(data, return: :primary_key)
87
92
  else
88
93
  upsert_texts(texts: texts, ids: ids)
89
94
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BxBuilderChain
4
- VERSION = "0.1.16"
4
+ VERSION = "0.1.17"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bx_builder_chain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Ketelle
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-02 00:00:00.000000000 Z
11
+ date: 2024-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk