Module: RagRuby
- Defined in:
- lib/rag_ruby.rb,
lib/rag_ruby/chunk.rb,
lib/rag_ruby/answer.rb,
lib/rag_ruby/source.rb,
lib/rag_ruby/version.rb,
lib/rag_ruby/document.rb,
lib/rag_ruby/pipeline.rb,
lib/rag_ruby/loaders/url.rb,
lib/rag_ruby/stores/base.rb,
lib/rag_ruby/stores/zvec.rb,
lib/rag_ruby/loaders/base.rb,
lib/rag_ruby/loaders/file.rb,
lib/rag_ruby/configuration.rb,
lib/rag_ruby/rails/railtie.rb,
lib/rag_ruby/stores/memory.rb,
lib/rag_ruby/embedders/base.rb,
lib/rag_ruby/embedders/onnx.rb,
lib/rag_ruby/generators/base.rb,
lib/rag_ruby/prompt_template.rb,
lib/rag_ruby/rails/indexable.rb,
lib/rag_ruby/embedders/cohere.rb,
lib/rag_ruby/embedders/ollama.rb,
lib/rag_ruby/embedders/openai.rb,
lib/rag_ruby/embedders/voyage.rb,
lib/rag_ruby/generators/gemini.rb,
lib/rag_ruby/generators/ollama.rb,
lib/rag_ruby/generators/openai.rb,
lib/rag_ruby/loaders/directory.rb,
lib/rag_ruby/generators/ruby_llm.rb,
lib/rag_ruby/generators/anthropic.rb,
lib/rag_ruby/loaders/active_record.rb,
lib/rag_ruby/embedders/hugging_face.rb
Defined Under Namespace
Modules: Embedders, Generators, Indexable, Loaders, Stores
Classes: Answer, Chunk, Configuration, ConfigurationError, Document, EmbeddingError, Error, GenerationError, Pipeline, PromptTemplate, Railtie, Source
Constant Summary
collapse
- VERSION =
"0.2.0"
Class Method Summary
collapse
Class Method Details
.ask(question, **opts) ⇒ Object
88
89
90
|
# File 'lib/rag_ruby.rb', line 88
def ask(question, **opts)
pipeline.query(question, **opts)
end
|
46
47
48
|
# File 'lib/rag_ruby.rb', line 46
def configure(&block)
@pipeline = Pipeline.new(&block)
end
|
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/rag_ruby.rb', line 50
def configure_from_hash(hash)
@pipeline = Pipeline.new do |config|
if (chunker_config = hash["chunker"])
config.chunker(
(chunker_config["strategy"] || "recursive_character").to_sym,
chunk_size: chunker_config["chunk_size"] || 1000,
chunk_overlap: chunker_config["chunk_overlap"] || 200
)
end
if (embedder_config = hash["embedder"])
provider = (embedder_config["provider"] || "openai").to_sym
opts = embedder_config.reject { |k, _| k == "provider" }
.transform_keys(&:to_sym)
config.embedder(provider, **opts)
end
if (store_config = hash["store"])
provider = (store_config["provider"] || "memory").to_sym
opts = store_config.reject { |k, _| k == "provider" }
.transform_keys(&:to_sym)
config.store(provider, **opts)
end
if (gen_config = hash["generator"])
provider = (gen_config["provider"] || "openai").to_sym
opts = gen_config.reject { |k, _| k == "provider" }
.transform_keys(&:to_sym)
config.generator(provider, **opts)
end
end
end
|
.pipeline ⇒ Object
42
43
44
|
# File 'lib/rag_ruby.rb', line 42
def pipeline
@pipeline ||= Pipeline.new
end
|
.reset! ⇒ Object
92
93
94
|
# File 'lib/rag_ruby.rb', line 92
def reset!
@pipeline = nil
end
|
.search(query, top_k: 5, filter: nil) ⇒ Object
83
84
85
86
|
# File 'lib/rag_ruby.rb', line 83
def search(query, top_k: 5, filter: nil)
embedding = pipeline.config.embedder_instance.embed(query)
pipeline.config.store_instance.search(embedding, top_k: top_k, filter: filter)
end
|