lib/baran/text_splitter.rb in baran-0.1.8 vs lib/baran/text_splitter.rb in baran-0.1.9
- old
+ new
@@ -12,16 +12,18 @@
def splitted(text)
raise NotImplementedError, "splitted method should be implemented in a subclass"
end
- def chunks(text)
+ def chunks(text, metadata: nil)
cursor = 0
chunks = []
splitted(text).compact.each do |chunk|
- chunks << { text: chunk, cursor: cursor }
+ chunk = { text: chunk, cursor: cursor }
+ chunk[:metadata] = metadata if metadata
+ chunks << chunk
cursor += chunk.length
end
chunks
end
@@ -54,6 +56,6 @@
results << joined(current_splits, separator)
results
end
end
-end
\ No newline at end of file
+end