llm_memory 0.1.0 → 0.1.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: c3f9540b8e3ca30d11eacd2e3100b4aa4ef985d041017b2b09bd5fad52d2f776
4
- data.tar.gz: 9998bca0ea546d93b3a051ac7a6c62a9597ae2da9e85d8d5b36aab4212c59641
3
+ metadata.gz: b81b1033f4e0ade103fd1c73317e0ef575244225ccce51fab50f232f2d138e37
4
+ data.tar.gz: 945bd74694fc40c020df96763dfe96df2b21d402648b2b7f948c526a49532b7c
5
5
  SHA512:
6
- metadata.gz: 9923ca576cf858eac89facf8da2f88d6284f7577366b252bb4e3ab197879a78035dfacba62e7890ab097dc193ee922f2b6abf16b321d4f1b09e6f1d30e4e9184
7
- data.tar.gz: 44ff089feebead7cc9e1ef8b555212d20a938fcd6a4c72c13cfb55ae3029ebf6699722ea42e977ac108375e5d91c83aad450177ec2b9ad1037f87a83b83eadf7
6
+ metadata.gz: 357abfa9fcc316129c40e3fc869cab7460812e32ea1005efa2b039b84d537f6a307f6fb80f112920bc0c3e4be2fe02fa0af94e8451b9f1e6280658e79513133b
7
+ data.tar.gz: 818c51b4c18f0277d99ec85dbf0e80c88d05caea894035cd0cbb90cab9e3853b2f760b4a1ff8690afa00172d1ae7656df1db2a7c24618d73fc5fafa39b855458
data/Gemfile CHANGED
@@ -13,3 +13,6 @@ gem "webmock", "~> 3.18.1"
13
13
  gem "ruby-openai"
14
14
  gem "tiktoken_ruby"
15
15
  gem "redis"
16
+ # dev
17
+ gem "dotenv"
18
+ gem "pry"
data/Gemfile.lock CHANGED
@@ -9,10 +9,12 @@ GEM
9
9
  addressable (2.8.4)
10
10
  public_suffix (>= 2.0.2, < 6.0)
11
11
  ast (2.4.2)
12
+ coderay (1.1.3)
12
13
  connection_pool (2.4.0)
13
14
  crack (0.4.5)
14
15
  rexml
15
16
  diff-lcs (1.5.0)
17
+ dotenv (2.8.1)
16
18
  faraday (2.7.4)
17
19
  faraday-net_http (>= 2.0, < 3.1)
18
20
  ruby2_keywords (>= 0.0.4)
@@ -23,10 +25,14 @@ GEM
23
25
  json (2.6.3)
24
26
  language_server-protocol (3.17.0.3)
25
27
  lint_roller (1.0.0)
28
+ method_source (1.0.0)
26
29
  multipart-post (2.3.0)
27
30
  parallel (1.23.0)
28
31
  parser (3.2.2.1)
29
32
  ast (~> 2.4.1)
33
+ pry (0.14.2)
34
+ coderay (~> 1.1)
35
+ method_source (~> 1.0)
30
36
  public_suffix (5.0.1)
31
37
  rainbow (3.1.1)
32
38
  rake (13.0.6)
@@ -81,6 +87,7 @@ GEM
81
87
  lint_roller (~> 1.0)
82
88
  rubocop-performance (~> 1.16.0)
83
89
  tiktoken_ruby (0.0.4-arm64-darwin)
90
+ tiktoken_ruby (0.0.4-x86_64-linux)
84
91
  unicode-display_width (2.4.2)
85
92
  vcr (6.1.0)
86
93
  webmock (3.18.1)
@@ -93,7 +100,9 @@ PLATFORMS
93
100
  x86_64-linux
94
101
 
95
102
  DEPENDENCIES
103
+ dotenv
96
104
  llm_memory!
105
+ pry
97
106
  rake (~> 13.0)
98
107
  redis
99
108
  rspec (~> 3.0)
data/README.md CHANGED
@@ -14,6 +14,9 @@ This enables better integration with systems such as Rails and web services whil
14
14
 
15
15
  ## LLM Memory Components
16
16
 
17
+ ![image](https://user-images.githubusercontent.com/1880965/236099477-421b2003-79d2-4a7c-8f80-1afac4fd616d.png)
18
+
19
+
17
20
  1. LlmMemory::Wernicke: Responsible for loading external data (currently from files). More loader types are planned for future development.
18
21
 
19
22
  > Wernicke's area in brain is involved in the comprehension of written and spoken language
@@ -28,15 +31,13 @@ This enables better integration with systems such as Rails and web services whil
28
31
 
29
32
  ## Installation
30
33
 
31
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
32
-
33
34
  Install the gem and add to the application's Gemfile by executing:
34
35
 
35
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
36
+ $ bundle add llm_memory
36
37
 
37
38
  If bundler is not being used to manage dependencies, install the gem by executing:
38
39
 
39
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
40
+ $ gem install llm_memory
40
41
 
41
42
  ### Setup
42
43
 
@@ -55,7 +56,7 @@ end
55
56
  To use LLM Memory, follow these steps:
56
57
 
57
58
  1. Install the gem: gem install llm_memory
58
- 2. Set up Redis with Redisearch module enabled
59
+ 2. Set up Redis with Redisearch module enabled - Go to [Reids Cloud](https://redis.com/redis-enterprise-cloud/overview/) and get the redis url
59
60
  3. Configure LLM Memory to connect to your Redis instance
60
61
  4. Use LlmMemory::Wernicke to load data from your external sources
61
62
  5. Use LlmMemory::Hippocampus to search for relevant information based on user queries
@@ -12,6 +12,7 @@ module LlmMemory
12
12
  temperature: 0.7,
13
13
  max_token: 4096
14
14
  )
15
+ LlmMemory.configure
15
16
  @prompt = prompt
16
17
  @model = model
17
18
  @messages = []
@@ -13,6 +13,8 @@ module LlmMemory
13
13
  store_name: :redis,
14
14
  index_name: "llm_memory"
15
15
  )
16
+ LlmMemory.configure
17
+
16
18
  embedding_class = EmbeddingManager.embeddings[embedding_name]
17
19
  raise "Embedding '#{embedding_name}' not found." unless embedding_class
18
20
  @embedding_instance = embedding_class.new
@@ -26,7 +28,20 @@ module LlmMemory
26
28
  @chunk_overlap = chunk_overlap
27
29
  end
28
30
 
31
+ # validate the document format
32
+ def validate_documents(documents)
33
+ is_valid = documents.all? do |hash|
34
+ hash.is_a?(Hash) &&
35
+ hash.key?(:content) && hash[:content].is_a?(String) &&
36
+ hash.key?(:metadata) && hash[:metadata].is_a?(Hash)
37
+ end
38
+ unless is_valid
39
+ raise "Your documents need to have an array of hashes (content: string and metadata: hash)"
40
+ end
41
+ end
42
+
29
43
  def memorize(docs)
44
+ validate_documents(docs)
30
45
  docs = make_chunks(docs)
31
46
  docs = add_vectors(docs)
32
47
  @store.create_index unless @store.index_exists?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LlmMemory
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/llm_memory.rb CHANGED
@@ -20,5 +20,4 @@ module LlmMemory
20
20
  self.configuration ||= Configuration.new
21
21
  yield(configuration) if block_given?
22
22
  end
23
- configure # init for default values
24
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: llm_memory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shohei Kameda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-04 00:00:00.000000000 Z
11
+ date: 2023-05-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: LLM Memory is a Ruby gem designed to provide large language models (LLMs)
14
14
  like ChatGPT with memory using in-context learning. This enables better integration