llm_memory_pgvector 0.1.2 → 0.1.4

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: 02a8d906cb751a0dffa89839cc7f293c970c618285c917ca5521ed9091f4cad0
4
- data.tar.gz: 7eeced97f49923746900caf68269041f93621f588cf743195aa4acdcdb725d8f
3
+ metadata.gz: 429622b6f10a9c12ecc17068730ebdefa18f23c06560347bd97201efd5ef97de
4
+ data.tar.gz: 7c6b463ccc7e5289a711635befa43ce075dc8169bba678803b5c54f5d05c2571
5
5
  SHA512:
6
- metadata.gz: c92ec2de76562dca9b5b3a8d0c0414858d58a73fc1cf43a575e96dd446016eb780f42ef4ae04354eec3bb63e615bef7f2efb4b6aae3a4faffc507e0a78efa781
7
- data.tar.gz: 8989283b6f74ffb336b479114aa3b5a43790442924f51582c5ab3e6402e7460fe3cabd466591877dfc6c9aaf0f95037a926c24fa8b506aa5ecfd2ce9b2ae3a35
6
+ metadata.gz: 2ee72e800eafc4ec006a4cc528345fa9d8b4911656ff773305046e65105499a300c7a7cc11ae34f274955600515bbf4e60cc8a77c432adae38fcbae8569fe903
7
+ data.tar.gz: 637159935cd9f9d33c230fbb2aaf46c64e55b8db35cf282747bc75ccff27742863a96d0d8853e8f4588991fa0bc67a98e7ca0b19312b1455f9167a4cef7d728a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- llm_memory_pgvector (0.1.1)
4
+ llm_memory_pgvector (0.1.4)
5
5
  llm_memory (~> 0.1.7)
6
6
  pg (~> 1.5.3)
7
7
  pgvector (~> 0.2.0)
data/README.md CHANGED
@@ -4,15 +4,13 @@ This is a Ruby plugin for the [llm_memory](https://github.com/shohey1226/llm_mem
4
4
 
5
5
  ## Installation
6
6
 
7
- 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.
8
-
9
7
  Install the gem and add to the application's Gemfile by executing:
10
8
 
11
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORGg
9
+ $ bundle add llm_memory_pgvector
12
10
 
13
11
  If bundler is not being used to manage dependencies, install the gem by executing:
14
12
 
15
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
13
+ $ gem install llm_memory_pgvector
16
14
 
17
15
  Plese don't forget to add `llm_memory`
18
16
 
@@ -41,14 +41,44 @@ module LlmMemoryPgvector
41
41
  @conn.exec("DROP TABLE IF EXISTS #{@index_name}")
42
42
  end
43
43
 
44
+ def list(id: [])
45
+ result = if id.empty?
46
+ @conn.exec("SELECT * FROM #{@index_name}")
47
+ else
48
+ placeholders = id.map.with_index(1) { |_, i| "$#{i}" }.join(",")
49
+ @conn.exec_params("SELECT * FROM #{@index_name} WHERE id IN (#{placeholders})", id)
50
+ end
51
+ result.entries
52
+ end
53
+
54
+ def delete(id)
55
+ result = @conn.exec_params("DELETE FROM #{@index_name} WHERE id = $1", [id])
56
+ result.cmd_tuples > 0
57
+ end
58
+
59
+ def get(id)
60
+ result = @conn.exec_params("SELECT * FROM #{@index_name} WHERE id = $1", [id])
61
+ result.entries.first
62
+ end
63
+
64
+ def delete_all
65
+ @conn.exec("DELETE FROM #{@index_name}")
66
+ true
67
+ rescue PG::Error
68
+ false
69
+ end
70
+
44
71
  # data = [{ content: "", vector: [], metadata: {} },,]
45
72
  def add(data: [])
73
+ new_ids = []
46
74
  data.each do |row|
47
- @conn.exec_params(
48
- "INSERT INTO #{@index_name} (#{@content_key}, #{@metadata_key}, #{@vector_key}) VALUES ($1, $2, $3)",
75
+ result = @conn.exec_params(
76
+ "INSERT INTO #{@index_name} (#{@content_key}, #{@metadata_key}, #{@vector_key}) VALUES ($1, $2, $3) RETURNING id",
49
77
  [row[@content_key.to_sym], row[@metadata_key.to_sym].to_json, row[@vector_key.to_sym]]
50
78
  )
79
+ new_ids << result[0]["id"].to_i if result && result[0] && result[0]["id"]
51
80
  end
81
+ list(id: new_ids)
52
82
  end
53
83
 
54
84
  def search(query: [], k: 3)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LlmMemoryPgvector
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: llm_memory_pgvector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
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-18 00:00:00.000000000 Z
11
+ date: 2023-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: llm_memory