llm_memory 0.1.11 → 0.1.13

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: c72d46a390a534d27ea5ee90bfb2950b75fd16f5320af2a431a314bcee13be30
4
- data.tar.gz: 974f529b0158cf5b4a8d4330dca59fe2fd3c2ee37cdca6465d98abee0f84db18
3
+ metadata.gz: 783f2bf830c8e3bf6ac8f033c200bcdc068ac51e23c444a15a28ce4c3fdb3faf
4
+ data.tar.gz: 0705cd834c8877f368bb8827e7916f72ec81d1e70839b2455fd27f030b1d9346
5
5
  SHA512:
6
- metadata.gz: 697d7a93bc637ec00004e68cd83dac1077e9705706e6b0123131acfaac201ce7979eeef63772bae35c53fa1b95ea7123f23399e5ee0ea1b454c689b6aa0f6a33
7
- data.tar.gz: ab67fd9ec6c1297b5308dfc28b9475bab46e28aa3b4f2af1694a9053ed7203c80e478320c11663a49583e43762814b85e0bdc52d2ea7002274a282609b1db9bd
6
+ metadata.gz: 6adf9915342427085ec647c1475f4169159d8670731b76100820bd13780d43ab7e74e31e36f8eed48453ea7f3a63dd1d4da11e784ab6124a16dfe0a853c17199
7
+ data.tar.gz: fecd053b1881b4d52a6f587469b7ffb50501d1e75b100eedc27a33039805dfdccb33b2904cb0482754bcbce9c5d034369364db28b7749bcd511eac51176c01a2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- llm_memory (0.1.11)
4
+ llm_memory (0.1.13)
5
5
  redis (~> 4.6.0)
6
6
  ruby-openai (~> 3.7.0)
7
7
  tokenizers (~> 0.3.3)
data/README.md CHANGED
@@ -54,8 +54,10 @@ end
54
54
 
55
55
  To use LLM Memory, follow these steps:
56
56
 
57
+ If you want to use pgvector instead of Redisearch. You can use the plugin. Please check the doc and change the setup steps(2&3)
58
+
57
59
  1. Install the gem: gem install llm_memory
58
- 2. Set up Redis with Redisearch module enabled - Go to [Reids Cloud](https://redis.com/redis-enterprise-cloud/overview/) and get the redis url
60
+ 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
61
  3. Configure LLM Memory to connect to your Redis instance
60
62
  4. Use LlmMemory::Wernicke to load data from your external sources
61
63
  5. Use LlmMemory::Hippocampus to search for relevant information based on user queries
@@ -71,12 +73,13 @@ docs = LlmMemory::Wernicke.load(:file, "/tmp/a_directory")
71
73
  # docs = [{
72
74
  # content: "Hi there",
73
75
  # metadata: {
74
- # file_name: "a.txt"
76
+ # file_name: "a.txt",
77
+ # timestamp: "20201231235959"
75
78
  # }
76
79
  # },,,]
77
80
 
78
81
  hippocampus = LlmMemory::Hippocampus.new
79
- hippocampus.memorize(docs)
82
+ res = hippocampus.memorize(docs)
80
83
 
81
84
  query_str = "What is my name?"
82
85
  related_docs = hippocampus.query(query_str, limit: 3)
@@ -57,6 +57,14 @@ module LlmMemory
57
57
  @store.drop_index if @store.index_exists?
58
58
  end
59
59
 
60
+ def forget(key)
61
+ @store.delete(key)
62
+ end
63
+
64
+ def list(array = [])
65
+ @store.list(array)
66
+ end
67
+
60
68
  def add_vectors(docs)
61
69
  # embed documents and add vector
62
70
  result = []
@@ -14,11 +14,13 @@ module LlmMemory
14
14
 
15
15
  file_name = File.basename(file_path)
16
16
  file_content = File.read(file_path)
17
+ ctime = File.ctime(file_path)
17
18
 
18
19
  files_array << {
19
20
  content: file_content,
20
21
  metadata: {
21
- file_name: file_name
22
+ file_name: file_name,
23
+ timestamp: ctime.strftime("%Y%m%d%H%M%S") # YYMMDDHHmmss
22
24
  }
23
25
  }
24
26
  end
@@ -27,6 +27,14 @@ module LlmMemory
27
27
  raise NotImplementedError, "Each store must implement the 'add' method."
28
28
  end
29
29
 
30
+ def list
31
+ raise NotImplementedError, "Each store must implement the 'list' method."
32
+ end
33
+
34
+ def delete
35
+ raise NotImplementedError, "Each store must implement the 'delete' method."
36
+ end
37
+
30
38
  def search
31
39
  raise NotImplementedError, "Each store must implement the 'search' method."
32
40
  end
@@ -79,7 +79,12 @@ module LlmMemory
79
79
  result = {}
80
80
  @client.pipelined do |pipeline|
81
81
  data.each_with_index do |d, i|
82
- key = "#{@index_name}:#{SecureRandom.uuid.delete("-")}"
82
+ key = @index_name # index_name:create_time:metadata_timestamp:uuid
83
+ timestamp = d.dig(:metadata, :timestamp)
84
+ key += ":#{Time.now.strftime("%Y%m%d%H%M%S")}"
85
+ key += ":#{timestamp}"
86
+ key += ":#{SecureRandom.hex(8)}"
87
+
83
88
  meta_json = d[:metadata].nil? ? "" : d[:metadata].to_json # serialize
84
89
  vector_value = d[:vector].map(&:to_f).pack("f*")
85
90
  pipeline.hset(
@@ -118,7 +123,33 @@ module LlmMemory
118
123
  puts "Unexpected Error: #{e.message}"
119
124
  end
120
125
 
121
- def delete
126
+ def delete(key)
127
+ @client.del(key) if @client.exists?(key)
128
+ end
129
+
130
+ def delete_all
131
+ list.keys.each do |key|
132
+ delete(key)
133
+ end
134
+ end
135
+
136
+ def list(patterns = [])
137
+ patterns = if patterns.empty?
138
+ ["#{@index_name}:*"]
139
+ else
140
+ patterns.map { |pattern| "#{@index_name}:#{pattern}" }
141
+ end
142
+ data = {}
143
+ patterns.each do |pattern|
144
+ @client.keys(pattern).each do |key|
145
+ obj = @client.hgetall(key)
146
+ data[key] = {
147
+ content: obj.dig("content"),
148
+ metadata: JSON.parse(obj.dig("metadata"))
149
+ }
150
+ end
151
+ end
152
+ data
122
153
  end
123
154
 
124
155
  def update
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LlmMemory
4
- VERSION = "0.1.11"
4
+ VERSION = "0.1.13"
5
5
  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.11
4
+ version: 0.1.13
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-07-02 00:00:00.000000000 Z
11
+ date: 2023-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tokenizers