langchainrb 0.6.19 → 0.7.0
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 +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/langchain/vectorsearch/pgvector.rb +0 -4
- data/lib/langchain/version.rb +1 -1
- data/lib/langchain.rb +0 -2
- metadata +6 -8
- data/lib/langchain/active_record/hooks.rb +0 -112
- data/lib/langchain/railtie.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4efc896c1c0fa895ebd11bdb3c4d5604ccd34878aa29472419efca85800072da
|
4
|
+
data.tar.gz: c703f8150c7a6a6cb802260da2eeb95d4f7542cc0c5490794cea844351b4fe7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18b0c48b747978b2a92ecd8d118f31b199d5f58469a5dd55ccbfc3a56a9044faf42784e4760ff9a9fca94da019107629c107a3fe586b7d55243aa92bd1c5b949
|
7
|
+
data.tar.gz: d8513d2018ce48a60fbecc9ca3efb91411385fd71301e0c79ac3612d91b2b504427f2ea19b41991f2f4b43a8bd3b650035684b02a46ae0b114d83343ef5bce18
|
data/CHANGELOG.md
CHANGED
data/lib/langchain/version.rb
CHANGED
data/lib/langchain.rb
CHANGED
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.
|
4
|
+
version: 0.7.0
|
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-10-
|
11
|
+
date: 2023-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: baran
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: zeitwerk
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 2.
|
75
|
+
version: '2.5'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 2.
|
82
|
+
version: '2.5'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: pragmatic_segmenter
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -539,7 +539,6 @@ files:
|
|
539
539
|
- LICENSE.txt
|
540
540
|
- README.md
|
541
541
|
- lib/langchain.rb
|
542
|
-
- lib/langchain/active_record/hooks.rb
|
543
542
|
- lib/langchain/agent/base.rb
|
544
543
|
- lib/langchain/agent/react_agent.rb
|
545
544
|
- lib/langchain/agent/react_agent/react_agent_prompt.yaml
|
@@ -601,7 +600,6 @@ files:
|
|
601
600
|
- lib/langchain/prompt/few_shot_prompt_template.rb
|
602
601
|
- lib/langchain/prompt/loading.rb
|
603
602
|
- lib/langchain/prompt/prompt_template.rb
|
604
|
-
- lib/langchain/railtie.rb
|
605
603
|
- lib/langchain/tool/base.rb
|
606
604
|
- lib/langchain/tool/calculator.rb
|
607
605
|
- lib/langchain/tool/database.rb
|
@@ -1,112 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Langchain
|
4
|
-
module ActiveRecord
|
5
|
-
# This module adds the following functionality to your ActiveRecord models:
|
6
|
-
# * `vectorsearch` class method to set the vector search provider
|
7
|
-
# * `similarity_search` class method to search for similar texts
|
8
|
-
# * `upsert_to_vectorsearch` instance method to upsert the record to the vector search provider
|
9
|
-
#
|
10
|
-
# Usage:
|
11
|
-
# class Recipe < ActiveRecord::Base
|
12
|
-
# vectorsearch provider: Langchain::Vectorsearch::Weaviate.new(
|
13
|
-
# api_key: ENV["WEAVIATE_API_KEY"],
|
14
|
-
# url: ENV["WEAVIATE_URL"],
|
15
|
-
# index_name: "Recipes",
|
16
|
-
# llm: Langchain::LLM::OpenAI.new(api_key: ENV["OPENAI_API_KEY"])
|
17
|
-
# )
|
18
|
-
#
|
19
|
-
# after_save :upsert_to_vectorsearch
|
20
|
-
#
|
21
|
-
# # Overwriting how the model is serialized before it's indexed
|
22
|
-
# def as_vector
|
23
|
-
# [
|
24
|
-
# "Title: #{title}",
|
25
|
-
# "Description: #{description}",
|
26
|
-
# ...
|
27
|
-
# ]
|
28
|
-
# .compact
|
29
|
-
# .join("\n")
|
30
|
-
# end
|
31
|
-
# end
|
32
|
-
#
|
33
|
-
# Create the default schema
|
34
|
-
# Recipe.class_variable_get(:@@provider).create_default_schema
|
35
|
-
# Query the vector search provider
|
36
|
-
# Recipe.similarity_search("carnivore dish")
|
37
|
-
# Delete the default schema to start over
|
38
|
-
# Recipe.class_variable_get(:@@provider).destroy_default_schema
|
39
|
-
#
|
40
|
-
module Hooks
|
41
|
-
def self.included(base)
|
42
|
-
base.extend ClassMethods
|
43
|
-
end
|
44
|
-
|
45
|
-
# Index the text to the vector search provider
|
46
|
-
# You'd typically call this method in an ActiveRecord callback
|
47
|
-
#
|
48
|
-
# @return [Boolean] true
|
49
|
-
# @raise [Error] Indexing to vector search DB failed
|
50
|
-
def upsert_to_vectorsearch
|
51
|
-
if previously_new_record?
|
52
|
-
self.class.class_variable_get(:@@provider).add_texts(
|
53
|
-
texts: [as_vector],
|
54
|
-
ids: [id]
|
55
|
-
)
|
56
|
-
else
|
57
|
-
self.class.class_variable_get(:@@provider).update_texts(
|
58
|
-
texts: [as_vector],
|
59
|
-
ids: [id]
|
60
|
-
)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
# Used to serialize the DB record to an indexable vector text
|
65
|
-
# Overwrite this method in your model to customize
|
66
|
-
#
|
67
|
-
# @return [String] the text representation of the model
|
68
|
-
def as_vector
|
69
|
-
to_json
|
70
|
-
end
|
71
|
-
|
72
|
-
module ClassMethods
|
73
|
-
# Set the vector search provider
|
74
|
-
#
|
75
|
-
# @param provider [Object] The `Langchain::Vectorsearch::*` instance
|
76
|
-
def vectorsearch(provider:)
|
77
|
-
class_variable_set(:@@provider, provider)
|
78
|
-
end
|
79
|
-
|
80
|
-
# Search for similar texts
|
81
|
-
#
|
82
|
-
# @param query [String] The query to search for
|
83
|
-
# @param k [Integer] The number of results to return
|
84
|
-
# @return [ActiveRecord::Relation] The ActiveRecord relation
|
85
|
-
def similarity_search(query, k: 1)
|
86
|
-
records = class_variable_get(:@@provider).similarity_search(
|
87
|
-
query: query,
|
88
|
-
k: k
|
89
|
-
)
|
90
|
-
|
91
|
-
# We use "__id" when Weaviate is the provider
|
92
|
-
ids = records.map { |record| record.dig("id") || record.dig("__id") }
|
93
|
-
where(id: ids)
|
94
|
-
end
|
95
|
-
|
96
|
-
# Ask a question and return the answer
|
97
|
-
#
|
98
|
-
# @param question [String] The question to ask
|
99
|
-
# @param k [Integer] The number of results to have in context
|
100
|
-
# @yield [String] Stream responses back one String at a time
|
101
|
-
# @return [String] The answer to the question
|
102
|
-
def ask(question:, k: 4, &block)
|
103
|
-
class_variable_get(:@@provider).ask(
|
104
|
-
question: question,
|
105
|
-
k: k,
|
106
|
-
&block
|
107
|
-
)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
data/lib/langchain/railtie.rb
DELETED