langchainrb 0.6.1 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +4 -4
- data/README.md +45 -11
- data/lib/langchain/active_record/hooks.rb +4 -2
- data/lib/langchain/vectorsearch/base.rb +10 -0
- data/lib/langchain/vectorsearch/chroma.rb +22 -4
- data/lib/langchain/vectorsearch/hnswlib.rb +2 -0
- data/lib/langchain/vectorsearch/milvus.rb +4 -0
- data/lib/langchain/vectorsearch/pgvector.rb +2 -0
- data/lib/langchain/vectorsearch/pinecone.rb +34 -4
- data/lib/langchain/vectorsearch/qdrant.rb +17 -5
- data/lib/langchain/vectorsearch/weaviate.rb +11 -4
- data/lib/langchain/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73f980d6a7dd67d0112038a8266a05f8b5697e05c98e61a94598d38406de7c8b
|
4
|
+
data.tar.gz: 8abc93ad6da8ad05d76ac35eff9aaab963c33549acb94bda4dd83daddeb71f4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b5450e51ee732a1e2414e3db5f8a46d113d0b537b561f95556756e2854c9bb9175c898388acc2bb8672b2479e647625d3166580b7b1b25eb6cdc86ff6d42aee
|
7
|
+
data.tar.gz: b5843004533f952782946e6a753aa5306c6ad4a5f97887416f8f10f4192ca1f88d00d30624cd62581022314649e5d291d9c1ab46f2bab31f9455860fc533c83d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.6.3] - 2023-06-25
|
4
|
+
- Add #destroy_default_schema() to Langchain::Vectorsearch::* classes
|
5
|
+
|
6
|
+
## [0.6.2] - 2023-06-25
|
7
|
+
- Qdrant, Chroma, and Pinecone are supported by ActiveRecord hooks
|
8
|
+
|
3
9
|
## [0.6.1] - 2023-06-24
|
4
10
|
- Adding support to hook vectorsearch into ActiveRecord models
|
5
11
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
langchainrb (0.6.
|
4
|
+
langchainrb (0.6.3)
|
5
5
|
baran (~> 0.1.6)
|
6
6
|
colorize (~> 0.8.1)
|
7
7
|
json-schema (~> 4.0.0)
|
@@ -133,7 +133,7 @@ GEM
|
|
133
133
|
faraday (>= 1.0)
|
134
134
|
faraday_middleware
|
135
135
|
graphql-client
|
136
|
-
graphql (2.0.
|
136
|
+
graphql (2.0.23)
|
137
137
|
graphql-client (0.18.0)
|
138
138
|
activesupport (>= 3.0)
|
139
139
|
graphql
|
@@ -298,7 +298,7 @@ GEM
|
|
298
298
|
tzinfo (2.0.6)
|
299
299
|
concurrent-ruby (~> 1.0)
|
300
300
|
unicode-display_width (2.4.2)
|
301
|
-
weaviate-ruby (0.8.
|
301
|
+
weaviate-ruby (0.8.3)
|
302
302
|
faraday (~> 1)
|
303
303
|
faraday_middleware (~> 1)
|
304
304
|
graphlient (~> 0.6.0)
|
@@ -346,7 +346,7 @@ DEPENDENCIES
|
|
346
346
|
safe_ruby (~> 1.0.4)
|
347
347
|
sequel (~> 5.68.0)
|
348
348
|
standardrb
|
349
|
-
weaviate-ruby (~> 0.8.
|
349
|
+
weaviate-ruby (~> 0.8.3)
|
350
350
|
wikipedia-client (~> 1.17.0)
|
351
351
|
yard
|
352
352
|
|
data/README.md
CHANGED
@@ -35,19 +35,19 @@ require "langchain"
|
|
35
35
|
|
36
36
|
| Database | Querying | Storage | Schema Management | Backups | Rails Integration |
|
37
37
|
| -------- |:------------------:| -------:| -----------------:| -------:| -----------------:|
|
38
|
-
| [Chroma](https://trychroma.com/) | :white_check_mark: | :white_check_mark: | :white_check_mark: | WIP |
|
38
|
+
| [Chroma](https://trychroma.com/) | :white_check_mark: | :white_check_mark: | :white_check_mark: | WIP | :white_check_mark: |
|
39
39
|
| [Hnswlib](https://github.com/nmslib/hnswlib/) | :white_check_mark: | :white_check_mark: | :white_check_mark: | WIP | WIP |
|
40
40
|
| [Milvus](https://milvus.io/) | :white_check_mark: | :white_check_mark: | :white_check_mark: | WIP | WIP |
|
41
|
-
| [Pinecone](https://www.pinecone.io/) | :white_check_mark: | :white_check_mark: | :white_check_mark: | WIP |
|
41
|
+
| [Pinecone](https://www.pinecone.io/) | :white_check_mark: | :white_check_mark: | :white_check_mark: | WIP | :white_check_mark: |
|
42
42
|
| [Pgvector](https://github.com/pgvector/pgvector) | :white_check_mark: | :white_check_mark: | :white_check_mark: | WIP | WIP |
|
43
|
-
| [Qdrant](https://qdrant.tech/) | :white_check_mark: | :white_check_mark: | :white_check_mark: | WIP |
|
43
|
+
| [Qdrant](https://qdrant.tech/) | :white_check_mark: | :white_check_mark: | :white_check_mark: | WIP | :white_check_mark: |
|
44
44
|
| [Weaviate](https://weaviate.io/) | :white_check_mark: | :white_check_mark: | :white_check_mark: | WIP | :white_check_mark: |
|
45
45
|
|
46
46
|
### Using Vector Search Databases 🔍
|
47
47
|
|
48
48
|
Choose the LLM provider you'll be using (OpenAI or Cohere) and retrieve the API key.
|
49
49
|
|
50
|
-
Add `gem "weaviate-ruby", "~> 0.8.
|
50
|
+
Add `gem "weaviate-ruby", "~> 0.8.3"` to your Gemfile.
|
51
51
|
|
52
52
|
Pick the vector search database you'll be using and instantiate the client:
|
53
53
|
```ruby
|
@@ -110,6 +110,22 @@ client.ask(
|
|
110
110
|
)
|
111
111
|
```
|
112
112
|
|
113
|
+
## Integrating Vector Search into ActiveRecord models
|
114
|
+
```ruby
|
115
|
+
class Product < ActiveRecord::Base
|
116
|
+
vectorsearch provider: Langchain::Vectorsearch::Qdrant.new(
|
117
|
+
api_key: ENV["QDRANT_API_KEY"],
|
118
|
+
url: ENV["QDRANT_URL"],
|
119
|
+
index_name: "Products",
|
120
|
+
llm: Langchain::LLM::GooglePalm.new(api_key: ENV["GOOGLE_PALM_API_KEY"])
|
121
|
+
)
|
122
|
+
|
123
|
+
after_save :upsert_to_vectorsearch
|
124
|
+
end
|
125
|
+
```
|
126
|
+
|
127
|
+
Additional info [here](https://github.com/andreibondarev/langchainrb/blob/main/lib/langchain/active_record/hooks.rb#L10-L38).
|
128
|
+
|
113
129
|
### Using Standalone LLMs 🗣️
|
114
130
|
|
115
131
|
Add `gem "ruby-openai", "~> 4.0.0"` to your Gemfile.
|
@@ -370,15 +386,33 @@ Langchain.logger.level = :info
|
|
370
386
|
Join us in the [Langchain.rb](https://discord.gg/WDARp7J2n8) Discord server.
|
371
387
|
|
372
388
|
## Core Contributors
|
373
|
-
[<img style="border-radius:50%" alt="Andrei Bondarev" src="https://avatars.githubusercontent.com/u/541665?v=4" width="80" height="80" class="avatar">](https://
|
389
|
+
[<img style="border-radius:50%" alt="Andrei Bondarev" src="https://avatars.githubusercontent.com/u/541665?v=4" width="80" height="80" class="avatar">](https://twitter.com/rushing_andrei)
|
374
390
|
|
375
|
-
##
|
376
|
-
[<img style="border-radius:50%" alt="Andrei Bondarev" src="https://avatars.githubusercontent.com/u/541665?v=4" width="80" height="80" class="avatar">](https://github.com/andreibondarev)
|
377
|
-
[<img style="border-radius:50%" alt="Rafael Figueiredo" src="https://avatars.githubusercontent.com/u/35845775?v=4" width="80" height="80" class="avatar">](https://github.com/rafaelqfigueiredo)
|
378
|
-
[<img style="border-radius:50%" alt="Ricky Chilcott" src="https://avatars.githubusercontent.com/u/445759?v=4" width="80" height="80" class="avatar">](https://github.com/rickychilcott)
|
391
|
+
## Contributors
|
379
392
|
[<img style="border-radius:50%" alt="Alex Chaplinsky" src="https://avatars.githubusercontent.com/u/695947?v=4" width="80" height="80" class="avatar">](https://github.com/alchaplinsky)
|
380
|
-
|
381
|
-
|
393
|
+
[<img style="border-radius:50%" alt="Josh Nichols" src="https://avatars.githubusercontent.com/u/159?v=4" width="80" height="80" class="avatar">](https://github.com/technicalpickles)
|
394
|
+
[<img style="border-radius:50%" alt="Matt Lindsey" src="https://avatars.githubusercontent.com/u/5638339?v=4" width="80" height="80" class="avatar">](https://github.com/mattlindsey)
|
395
|
+
[<img style="border-radius:50%" alt="Ricky Chilcott" src="https://avatars.githubusercontent.com/u/445759?v=4" width="80" height="80" class="avatar">](https://github.com/rickychilcott)
|
396
|
+
[<img style="border-radius:50%" alt="Moeki Kawakami" src="https://avatars.githubusercontent.com/u/72325947?v=4" width="80" height="80" class="avatar">](https://github.com/moekidev)
|
397
|
+
[<img style="border-radius:50%" alt="Jens Stmrs" src="https://avatars.githubusercontent.com/u/3492669?v=4" width="80" height="80" class="avatar">](https://github.com/faustus7)
|
398
|
+
[<img style="border-radius:50%" alt="Rafael Figueiredo" src="https://avatars.githubusercontent.com/u/35845775?v=4" width="80" height="80" class="avatar">](https://github.com/rafaelqfigueiredo)
|
399
|
+
[<img style="border-radius:50%" alt="Piero Dotti" src="https://avatars.githubusercontent.com/u/5167659?v=4" width="80" height="80" class="avatar">](https://github.com/ProGM)
|
400
|
+
[<img style="border-radius:50%" alt="Michał Ciemięga" src="https://avatars.githubusercontent.com/u/389828?v=4" width="80" height="80" class="avatar">](https://github.com/zewelor)
|
401
|
+
[<img style="border-radius:50%" alt="Bruno Bornsztein" src="https://avatars.githubusercontent.com/u/3760?v=4" width="80" height="80" class="avatar">](https://github.com/bborn)
|
402
|
+
[<img style="border-radius:50%" alt="Tim Williams" src="https://avatars.githubusercontent.com/u/1192351?v=4" width="80" height="80" class="avatar">](https://github.com/timrwilliams)
|
403
|
+
[<img style="border-radius:50%" alt="Zhenhang Tung" src="https://avatars.githubusercontent.com/u/8170159?v=4" width="80" height="80" class="avatar">](https://github.com/ZhenhangTung)
|
404
|
+
[<img style="border-radius:50%" alt="Hama" src="https://avatars.githubusercontent.com/u/38002468?v=4" width="80" height="80" class="avatar">](https://github.com/akmhmgc)
|
405
|
+
[<img style="border-radius:50%" alt="Josh Weir" src="https://avatars.githubusercontent.com/u/10720337?v=4" width="80" height="80" class="avatar">](https://github.com/joshweir)
|
406
|
+
[<img style="border-radius:50%" alt="Arthur Hess" src="https://avatars.githubusercontent.com/u/446035?v=4" width="80" height="80" class="avatar">](https://github.com/arthurhess)
|
407
|
+
[<img style="border-radius:50%" alt="Jin Shen" src="https://avatars.githubusercontent.com/u/54917718?v=4" width="80" height="80" class="avatar">](https://github.com/jacshen-ebay)
|
408
|
+
[<img style="border-radius:50%" alt="Earle Bunao" src="https://avatars.githubusercontent.com/u/4653624?v=4" width="80" height="80" class="avatar">](https://github.com/erbunao)
|
409
|
+
[<img style="border-radius:50%" alt="Maël H." src="https://avatars.githubusercontent.com/u/61985678?v=4" width="80" height="80" class="avatar">](https://github.com/mael-ha)
|
410
|
+
[<img style="border-radius:50%" alt="Chris O. Adebiyi" src="https://avatars.githubusercontent.com/u/62605573?v=4" width="80" height="80" class="avatar">](https://github.com/oluvvafemi)
|
411
|
+
[<img style="border-radius:50%" alt="Aaron Breckenridge" src="https://avatars.githubusercontent.com/u/201360?v=4" width="80" height="80" class="avatar">](https://github.com/breckenedge)
|
412
|
+
|
413
|
+
## Star History
|
414
|
+
|
415
|
+
[![Star History Chart](https://api.star-history.com/svg?repos=andreibondarev/langchainrb&type=Date)](https://star-history.com/#andreibondarev/langchainrb&Date)
|
382
416
|
|
383
417
|
## Contributing
|
384
418
|
|
@@ -35,7 +35,7 @@ module Langchain
|
|
35
35
|
# Query the vector search provider
|
36
36
|
# Recipe.similarity_search("carnivore dish")
|
37
37
|
# Delete the default schema to start over
|
38
|
-
# Recipe.class_variable_get(:@@provider).
|
38
|
+
# Recipe.class_variable_get(:@@provider).destroy_default_schema
|
39
39
|
#
|
40
40
|
module Hooks
|
41
41
|
def self.included(base)
|
@@ -87,7 +87,9 @@ module Langchain
|
|
87
87
|
query: query,
|
88
88
|
k: k
|
89
89
|
)
|
90
|
-
|
90
|
+
|
91
|
+
# We use "__id" when Weaviate is the provider
|
92
|
+
ids = records.map { |record| record.dig("id") || record.dig("__id") }
|
91
93
|
where(id: ids)
|
92
94
|
end
|
93
95
|
end
|
@@ -103,11 +103,21 @@ module Langchain::Vectorsearch
|
|
103
103
|
raise NotImplementedError, "#{self.class.name} does not support creating a default schema"
|
104
104
|
end
|
105
105
|
|
106
|
+
# Method supported by Vectorsearch DB to delete the default schema
|
107
|
+
def destroy_default_schema
|
108
|
+
raise NotImplementedError, "#{self.class.name} does not support deleting a default schema"
|
109
|
+
end
|
110
|
+
|
106
111
|
# Method supported by Vectorsearch DB to add a list of texts to the index
|
107
112
|
def add_texts(...)
|
108
113
|
raise NotImplementedError, "#{self.class.name} does not support adding texts"
|
109
114
|
end
|
110
115
|
|
116
|
+
# Method supported by Vectorsearch DB to update a list of texts to the index
|
117
|
+
def update_texts(...)
|
118
|
+
raise NotImplementedError, "#{self.class.name} does not support updating texts"
|
119
|
+
end
|
120
|
+
|
111
121
|
# Method supported by Vectorsearch DB to search for similar texts in the index
|
112
122
|
def similarity_search(...)
|
113
123
|
raise NotImplementedError, "#{self.class.name} does not support similarity search"
|
@@ -32,11 +32,10 @@ module Langchain::Vectorsearch
|
|
32
32
|
# Add a list of texts to the index
|
33
33
|
# @param texts [Array] The list of texts to add
|
34
34
|
# @return [Hash] The response from the server
|
35
|
-
def add_texts(texts:)
|
36
|
-
embeddings = Array(texts).map do |text|
|
35
|
+
def add_texts(texts:, ids: [])
|
36
|
+
embeddings = Array(texts).map.with_index do |text, i|
|
37
37
|
::Chroma::Resources::Embedding.new(
|
38
|
-
|
39
|
-
id: SecureRandom.uuid,
|
38
|
+
id: ids[i] ? ids[i].to_s : SecureRandom.uuid,
|
40
39
|
embedding: llm.embed(text: text),
|
41
40
|
# TODO: Add support for passing metadata
|
42
41
|
metadata: [], # metadatas[index],
|
@@ -48,12 +47,31 @@ module Langchain::Vectorsearch
|
|
48
47
|
collection.add(embeddings)
|
49
48
|
end
|
50
49
|
|
50
|
+
def update_texts(texts:, ids:)
|
51
|
+
embeddings = Array(texts).map.with_index do |text, i|
|
52
|
+
::Chroma::Resources::Embedding.new(
|
53
|
+
id: ids[i].to_s,
|
54
|
+
embedding: llm.embed(text: text),
|
55
|
+
# TODO: Add support for passing metadata
|
56
|
+
metadata: [], # metadatas[index],
|
57
|
+
document: text # Do we actually need to store the whole original document?
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
collection.update(embeddings)
|
62
|
+
end
|
63
|
+
|
51
64
|
# Create the collection with the default schema
|
52
65
|
# @return [Hash] The response from the server
|
53
66
|
def create_default_schema
|
54
67
|
::Chroma::Resources::Collection.create(index_name)
|
55
68
|
end
|
56
69
|
|
70
|
+
# TODO: Uncomment and add the spec
|
71
|
+
# def destroy_default_schema
|
72
|
+
# ::Chroma::Resources::Collection.delete(index_name)
|
73
|
+
# end
|
74
|
+
|
57
75
|
# Search for similar texts
|
58
76
|
# @param query [String] The text to search for
|
59
77
|
# @param k [Integer] The number of results to return
|
@@ -39,6 +39,8 @@ module Langchain::Vectorsearch
|
|
39
39
|
)
|
40
40
|
end
|
41
41
|
|
42
|
+
# TODO: Add update_texts method
|
43
|
+
|
42
44
|
# Create default schema
|
43
45
|
# @return [Hash] The response from the server
|
44
46
|
def create_default_schema
|
@@ -77,6 +79,8 @@ module Langchain::Vectorsearch
|
|
77
79
|
)
|
78
80
|
end
|
79
81
|
|
82
|
+
# TODO: Add destroy_default_schema method
|
83
|
+
|
80
84
|
def similarity_search(query:, k: 4)
|
81
85
|
embedding = llm.embed(text: query)
|
82
86
|
|
@@ -33,14 +33,14 @@ module Langchain::Vectorsearch
|
|
33
33
|
|
34
34
|
# Add a list of texts to the index
|
35
35
|
# @param texts [Array] The list of texts to add
|
36
|
+
# @param ids [Array] The list of IDs to add
|
36
37
|
# @param namespace [String] The namespace to add the texts to
|
37
38
|
# @param metadata [Hash] The metadata to use for the texts
|
38
39
|
# @return [Hash] The response from the server
|
39
|
-
def add_texts(texts:, namespace: "", metadata: nil)
|
40
|
-
vectors = texts.map do |text|
|
40
|
+
def add_texts(texts:, ids: [], namespace: "", metadata: nil)
|
41
|
+
vectors = texts.map.with_index do |text, i|
|
41
42
|
{
|
42
|
-
|
43
|
-
id: SecureRandom.uuid,
|
43
|
+
id: ids[i] ? ids[i].to_s : SecureRandom.uuid,
|
44
44
|
metadata: metadata || {content: text},
|
45
45
|
values: llm.embed(text: text)
|
46
46
|
}
|
@@ -51,6 +51,24 @@ module Langchain::Vectorsearch
|
|
51
51
|
index.upsert(vectors: vectors, namespace: namespace)
|
52
52
|
end
|
53
53
|
|
54
|
+
# Update a list of texts in the index
|
55
|
+
# @param texts [Array] The list of texts to update
|
56
|
+
# @param ids [Array] The list of IDs to update
|
57
|
+
# @param namespace [String] The namespace to update the texts in
|
58
|
+
# @param metadata [Hash] The metadata to use for the texts
|
59
|
+
# @return [Array] The response from the server
|
60
|
+
def update_texts(texts:, ids:, namespace: "", metadata: nil)
|
61
|
+
texts.map.with_index do |text, i|
|
62
|
+
# Pinecone::Vector#update ignore args when it is empty
|
63
|
+
index.update(
|
64
|
+
namespace: namespace,
|
65
|
+
id: ids[i].to_s,
|
66
|
+
values: llm.embed(text: text),
|
67
|
+
set_metadata: metadata
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
54
72
|
# Create the index with the default schema
|
55
73
|
# @return [Hash] The response from the server
|
56
74
|
def create_default_schema
|
@@ -61,6 +79,12 @@ module Langchain::Vectorsearch
|
|
61
79
|
)
|
62
80
|
end
|
63
81
|
|
82
|
+
# Delete the index
|
83
|
+
# @return [Hash] The response from the server
|
84
|
+
def destroy_default_schema
|
85
|
+
client.delete_index(index_name)
|
86
|
+
end
|
87
|
+
|
64
88
|
# Search for similar texts
|
65
89
|
# @param query [String] The text to search for
|
66
90
|
# @param k [Integer] The number of results to return
|
@@ -122,5 +146,11 @@ module Langchain::Vectorsearch
|
|
122
146
|
|
123
147
|
llm.chat(prompt: prompt)
|
124
148
|
end
|
149
|
+
|
150
|
+
# Pinecone index
|
151
|
+
# @return [Object] The Pinecone index
|
152
|
+
private def index
|
153
|
+
client.index(index_name)
|
154
|
+
end
|
125
155
|
end
|
126
156
|
end
|
@@ -32,11 +32,11 @@ module Langchain::Vectorsearch
|
|
32
32
|
# Add a list of texts to the index
|
33
33
|
# @param texts [Array] The list of texts to add
|
34
34
|
# @return [Hash] The response from the server
|
35
|
-
def add_texts(texts:)
|
35
|
+
def add_texts(texts:, ids:)
|
36
36
|
batch = {ids: [], vectors: [], payloads: []}
|
37
37
|
|
38
|
-
Array(texts).
|
39
|
-
batch[:ids].push(SecureRandom.uuid)
|
38
|
+
Array(texts).each_with_index do |text, i|
|
39
|
+
batch[:ids].push(ids[i] || SecureRandom.uuid)
|
40
40
|
batch[:vectors].push(llm.embed(text: text))
|
41
41
|
batch[:payloads].push({content: text})
|
42
42
|
end
|
@@ -47,6 +47,16 @@ module Langchain::Vectorsearch
|
|
47
47
|
)
|
48
48
|
end
|
49
49
|
|
50
|
+
def update_texts(texts:, ids:)
|
51
|
+
add_texts(texts: texts, ids: ids)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Deletes the default schema
|
55
|
+
# @return [Hash] The response from the server
|
56
|
+
def destroy_default_schema
|
57
|
+
client.collections.delete(collection_name: index_name)
|
58
|
+
end
|
59
|
+
|
50
60
|
# Create the index with the default schema
|
51
61
|
# @return [Hash] The response from the server
|
52
62
|
def create_default_schema
|
@@ -83,12 +93,14 @@ module Langchain::Vectorsearch
|
|
83
93
|
embedding:,
|
84
94
|
k: 4
|
85
95
|
)
|
86
|
-
client.points.search(
|
96
|
+
response = client.points.search(
|
87
97
|
collection_name: index_name,
|
88
98
|
limit: k,
|
89
99
|
vector: embedding,
|
90
|
-
with_payload: true
|
100
|
+
with_payload: true,
|
101
|
+
with_vector: true
|
91
102
|
)
|
103
|
+
response.dig("result")
|
92
104
|
end
|
93
105
|
|
94
106
|
# Ask a question and return the answer
|
@@ -5,7 +5,7 @@ module Langchain::Vectorsearch
|
|
5
5
|
#
|
6
6
|
# Wrapper around Weaviate
|
7
7
|
#
|
8
|
-
# Gem requirements: gem "weaviate-ruby", "~> 0.8.
|
8
|
+
# Gem requirements: gem "weaviate-ruby", "~> 0.8.3"
|
9
9
|
#
|
10
10
|
# Usage:
|
11
11
|
# weaviate = Langchain::Vectorsearch::Weaviate.new(url:, api_key:, index_name:, llm:, llm_api_key:)
|
@@ -35,7 +35,7 @@ module Langchain::Vectorsearch
|
|
35
35
|
# Add a list of texts to the index
|
36
36
|
# @param texts [Array] The list of texts to add
|
37
37
|
# @return [Hash] The response from the server
|
38
|
-
def add_texts(texts:, ids:)
|
38
|
+
def add_texts(texts:, ids: [])
|
39
39
|
client.objects.batch_create(
|
40
40
|
objects: weaviate_objects(texts, ids)
|
41
41
|
)
|
@@ -72,6 +72,7 @@ module Langchain::Vectorsearch
|
|
72
72
|
end
|
73
73
|
|
74
74
|
# Create default schema
|
75
|
+
# @return [Hash] The response from the server
|
75
76
|
def create_default_schema
|
76
77
|
client.schema.create(
|
77
78
|
class_name: index_name,
|
@@ -84,6 +85,12 @@ module Langchain::Vectorsearch
|
|
84
85
|
)
|
85
86
|
end
|
86
87
|
|
88
|
+
# Delete the index
|
89
|
+
# @return [Boolean] Whether the index was deleted
|
90
|
+
def destroy_default_schema
|
91
|
+
client.schema.delete(class_name: index_name)
|
92
|
+
end
|
93
|
+
|
87
94
|
# Return documents similar to the query
|
88
95
|
# @param query [String] The query to search for
|
89
96
|
# @param k [Integer|String] The number of results to return
|
@@ -127,13 +134,13 @@ module Langchain::Vectorsearch
|
|
127
134
|
|
128
135
|
private
|
129
136
|
|
130
|
-
def weaviate_objects(texts, ids)
|
137
|
+
def weaviate_objects(texts, ids = [])
|
131
138
|
Array(texts).map.with_index do |text, i|
|
132
139
|
weaviate_object(text, ids[i])
|
133
140
|
end
|
134
141
|
end
|
135
142
|
|
136
|
-
def weaviate_object(text, id)
|
143
|
+
def weaviate_object(text, id = nil)
|
137
144
|
{
|
138
145
|
class: index_name,
|
139
146
|
properties: {
|
data/lib/langchain/version.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.6.
|
4
|
+
version: 0.6.3
|
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-06-
|
11
|
+
date: 2023-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: baran
|
@@ -436,14 +436,14 @@ dependencies:
|
|
436
436
|
requirements:
|
437
437
|
- - "~>"
|
438
438
|
- !ruby/object:Gem::Version
|
439
|
-
version: 0.8.
|
439
|
+
version: 0.8.3
|
440
440
|
type: :development
|
441
441
|
prerelease: false
|
442
442
|
version_requirements: !ruby/object:Gem::Requirement
|
443
443
|
requirements:
|
444
444
|
- - "~>"
|
445
445
|
- !ruby/object:Gem::Version
|
446
|
-
version: 0.8.
|
446
|
+
version: 0.8.3
|
447
447
|
- !ruby/object:Gem::Dependency
|
448
448
|
name: wikipedia-client
|
449
449
|
requirement: !ruby/object:Gem::Requirement
|