Skip to content

Commit

Permalink
added list and delete
Browse files Browse the repository at this point in the history
  • Loading branch information
shohey1226 committed Jul 31, 2023
1 parent e6593e3 commit faf8ac0
Show file tree
Hide file tree
Showing 10 changed files with 18,886 additions and 13,905 deletions.
8 changes: 8 additions & 0 deletions lib/llm_memory/hippocampus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ def forget_all
@store.drop_index if @store.index_exists?
end

def forget(key)
@store.delete(key)
end

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

def add_vectors(docs)
# embed documents and add vector
result = []
Expand Down
8 changes: 8 additions & 0 deletions lib/llm_memory/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ def add
raise NotImplementedError, "Each store must implement the 'add' method."
end

def list
raise NotImplementedError, "Each store must implement the 'list' method."
end

def delete
raise NotImplementedError, "Each store must implement the 'delete' method."
end

def search
raise NotImplementedError, "Each store must implement the 'search' method."
end
Expand Down
28 changes: 27 additions & 1 deletion lib/llm_memory/stores/redis_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,33 @@ def add(data: [])
puts "Unexpected Error: #{e.message}"
end

def delete
def delete(key)
@client.del(key) if @client.exists?(key)
end

def delete_all
list.keys.each do |key|
delete(key)
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
end

def update
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit faf8ac0

Please sign in to comment.