Skip to content

Commit

Permalink
Merge pull request #5 from shohey1226/fix_list
Browse files Browse the repository at this point in the history
fixed list
  • Loading branch information
shohey1226 committed Aug 1, 2023
2 parents a3b915e + 6af323d commit e1d4dab
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ GEM
json (2.6.3)
language_server-protocol (3.17.0.3)
lint_roller (1.0.0)
llm_memory_pgvector (0.1.2)
llm_memory_pgvector (0.1.4)
llm_memory (~> 0.1.7)
pg (~> 1.5.3)
pgvector (~> 0.2.0)
Expand All @@ -35,7 +35,7 @@ GEM
parser (3.2.2.1)
ast (~> 2.4.1)
pg (1.5.3)
pgvector (0.2.0)
pgvector (0.2.1)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
Expand Down
8 changes: 6 additions & 2 deletions lib/llm_memory/hippocampus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ def forget(key)
@store.delete(key)
end

def list(array = [])
@store.list(array)
def list(*args)
@store.list(*args)
end

def get(key)
@store.get(key)
end

def add_vectors(docs)
Expand Down
24 changes: 7 additions & 17 deletions lib/llm_memory/stores/redis_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,13 @@ def delete_all
end
end

def list(patterns = [])
patterns = if patterns.empty?
["#{@index_name}:*"]
else
patterns.map { |pattern| "#{@index_name}:#{pattern}" }
end
data = {}
patterns.each do |pattern|
@client.keys(pattern).each do |key|
obj = @client.hgetall(key)
data[key] = {
content: obj.dig("content"),
metadata: JSON.parse(obj.dig("metadata"))
}
end
end
data
def get(key)
@client.hgetall(key)
end

def list(*args)
pattern = "#{@index_name}:#{args.first || "*"}"
@client.keys(pattern)
end

def update
Expand Down
4 changes: 2 additions & 2 deletions spec/llm_memory/hippocampus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
hippocampus.forget_all
res = hippocampus.memorize(docs)
expect(res.keys.map { |k| k.split(":")[2] }.uniq.first).to eq timestamp
expect(hippocampus.list.keys.sort).to eq res.keys.sort
expect(hippocampus.list.sort).to eq res.keys.sort
expect(res.values.first).to eq("Hello, I'm Shohei.")
hippocampus.forget(res.keys.first)
expect(hippocampus.list.keys.size).to eq(2)
expect(hippocampus.list("*:#{timestamp}:*").size).to eq(2)
end
end

Expand Down

0 comments on commit e1d4dab

Please sign in to comment.