langchainrb 0.11.0 → 0.11.1

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: 18814b2bd22af2484ef0358ad83b144a80d1d814e95dcae3bbfd36409d08487b
4
- data.tar.gz: ceac615304514e3a19e201b15af41fa0652c7fed8d81caf26bc643b4211b4e45
3
+ metadata.gz: '08b38ee39600716a9854a387fc0b54091290f27d7afa88b276a480651049bdd4'
4
+ data.tar.gz: 69d4292c129e751d9d4001912f5ab54ba23f9d9944a5e4294f4ba1dd426d401e
5
5
  SHA512:
6
- metadata.gz: 5ac5b9e6e3e846ca56ef080b1329f88d136a1df652a882a3c4f80fccb1ef10a5d1e3649a23332715147bfc35e44ed541d32155e7d23e77483c49f2cf85090886
7
- data.tar.gz: 94f99281fdabaa37ebe0da64f231cf4c12fce588f97ea17dddd30f6800e8c4a914592a9e896ab2c7dcf7728582f05c4fc04482eb0b696391420d557f02ba57c9
6
+ metadata.gz: 3f7d4403d11076fcff2975c88a236fa8b6ace079d83b774000af1d59c08f36794057eaef56769a51bb8e21ab462bba9dbf9df60d704f285b788af8a67b6977ea
7
+ data.tar.gz: 5d14c72130cada67dadfe880b2a0d723b312d8c27e7ef46452aa4ad65dce1055b66d8459b24c4b6d3f1adb5eeacf30c9fdc686b0190809ef051d393c33d3d33d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.11.0]
4
+ - Langchain::Tool::Vectorsearch that wraps Langchain::Vectorsearch::* classes. This allows the Assistant to call the tool and inject data from vector DBs.
5
+
3
6
  ## [0.11.0]
4
7
  - Delete previously deprecated `Langchain::Agent::ReActAgent` and `Langchain::Agent::SQLQueryAgent` classes
5
8
  - New `Langchain::Agent::FileSystem` tool that can read files, write to files, and list the contents of a directory
@@ -0,0 +1,24 @@
1
+ [
2
+ {
3
+ "type": "function",
4
+ "function": {
5
+ "name": "vectorsearch-similarity_search",
6
+ "description": "Vectorsearch: Retrieves relevant document for the query",
7
+ "parameters": {
8
+ "type": "object",
9
+ "properties": {
10
+ "query": {
11
+ "type": "string",
12
+ "description": "Query to find similar documents for"
13
+ },
14
+ "k": {
15
+ "type": "integer",
16
+ "description": "Number of similar documents to retrieve",
17
+ "default": 4
18
+ }
19
+ },
20
+ "required": ["query"]
21
+ }
22
+ }
23
+ }
24
+ ]
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Langchain::Tool
4
+ class Vectorsearch < Base
5
+ #
6
+ # A tool wraps vectorsearch classes
7
+ #
8
+ # Usage:
9
+ # # Initialize the LLM that will be used to generate embeddings
10
+ # ollama = Langchain::LLM::Ollama.new(url: ENV["OLLAMA_URL"]
11
+ # chroma = Langchain::Vectorsearch::Chroma.new(url: ENV["CHROMA_URL"], index_name: "my_index", llm: ollama)
12
+ #
13
+ # # This tool can now be used by the Assistant
14
+ # vectorsearch_tool = Langchain::Tool::Vectorsearch.new(vectorsearch: chroma)
15
+ #
16
+ NAME = "vectorsearch"
17
+ ANNOTATIONS_PATH = Langchain.root.join("./langchain/tool/#{NAME}/#{NAME}.json").to_path
18
+
19
+ attr_reader :vectorsearch
20
+
21
+ # Initializes the Vectorsearch tool
22
+ #
23
+ # @param vectorsearch [Langchain::Vectorsearch::Base] Vectorsearch instance to use
24
+ def initialize(vectorsearch:)
25
+ @vectorsearch = vectorsearch
26
+ end
27
+
28
+ # Executes the vector search and returns the results
29
+ #
30
+ # @param query [String] The query to search for
31
+ # @param k [Integer] The number of results to return
32
+ def similarity_search(query:, k: 4)
33
+ vectorsearch.similarity_search(query:, k: 4)
34
+ end
35
+ end
36
+ end
@@ -9,7 +9,7 @@ module Langchain::Vectorsearch
9
9
  # gem "weaviate-ruby", "~> 0.8.9"
10
10
  #
11
11
  # Usage:
12
- # weaviate = Langchain::Vectorsearch::Weaviate.new(url:, api_key:, index_name:, llm:)
12
+ # weaviate = Langchain::Vectorsearch::Weaviate.new(url: ENV["WEAVIATE_URL"], api_key: ENV["WEAVIATE_API_KEY"], index_name: "Docs", llm: llm)
13
13
  #
14
14
 
15
15
  # Initialize the Weaviate adapter
@@ -71,6 +71,22 @@ module Langchain::Vectorsearch
71
71
  end
72
72
  end
73
73
 
74
+ # Deletes a list of texts in the index
75
+ # @param ids [Array] The ids of texts to delete
76
+ # @return [Hash] The response from the server
77
+ def remove_texts(ids:)
78
+ raise ArgumentError, "ids must be an array" unless ids.is_a?(Array)
79
+
80
+ client.objects.batch_delete(
81
+ class_name: index_name,
82
+ where: {
83
+ path: ["__id"],
84
+ operator: "ContainsAny",
85
+ valueTextArray: ids
86
+ }
87
+ )
88
+ end
89
+
74
90
  # Create default schema
75
91
  # @return [Hash] The response from the server
76
92
  def create_default_schema
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Langchain
4
- VERSION = "0.11.0"
4
+ VERSION = "0.11.1"
5
5
  end
data/lib/langchain.rb CHANGED
@@ -31,6 +31,7 @@ loader.collapse("#{__dir__}/langchain/tool/database")
31
31
  loader.collapse("#{__dir__}/langchain/tool/file_system")
32
32
  loader.collapse("#{__dir__}/langchain/tool/google_search")
33
33
  loader.collapse("#{__dir__}/langchain/tool/ruby_code_interpreter")
34
+ loader.collapse("#{__dir__}/langchain/tool/vectorsearch")
34
35
  loader.collapse("#{__dir__}/langchain/tool/weather")
35
36
  loader.collapse("#{__dir__}/langchain/tool/wikipedia")
36
37
 
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.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Bondarev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-05 00:00:00.000000000 Z
11
+ date: 2024-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -776,6 +776,8 @@ files:
776
776
  - lib/langchain/tool/google_search/google_search.rb
777
777
  - lib/langchain/tool/ruby_code_interpreter/ruby_code_interpreter.json
778
778
  - lib/langchain/tool/ruby_code_interpreter/ruby_code_interpreter.rb
779
+ - lib/langchain/tool/vectorsearch/vectorsearch.json
780
+ - lib/langchain/tool/vectorsearch/vectorsearch.rb
779
781
  - lib/langchain/tool/weather/weather.json
780
782
  - lib/langchain/tool/weather/weather.rb
781
783
  - lib/langchain/tool/wikipedia/wikipedia.json