lsh 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/lsh/storage/redis_backend.rb +18 -7
  2. metadata +1 -1
@@ -35,8 +35,18 @@ module LSH
35
35
  end
36
36
 
37
37
  def reset!
38
- @redis.flushall
38
+ clear_data!
39
+ clear_projections!
40
+ end
41
+
42
+ def clear_data!
43
+ @redis.del(@redis.keys("lsh:bucket:*"))
39
44
  delete_dat_files_in_dir(@data_dir)
45
+ end
46
+
47
+ def clear_projections!
48
+ @redis.del("lsh:parameters")
49
+ @redis.del("lsh:buckets")
40
50
  delete_dat_files_in_dir(File.join(@data_dir, 'projections'))
41
51
  end
42
52
 
@@ -49,7 +59,7 @@ module LSH
49
59
  end
50
60
 
51
61
  def number_of_buckets
52
- @redis.get("buckets").to_i || 0
62
+ @redis.get("lsh:buckets").to_i || 0
53
63
  end
54
64
 
55
65
  def projections=(projections)
@@ -82,13 +92,13 @@ module LSH
82
92
 
83
93
  def parameters=(parms)
84
94
  parms[:window] = 'Infinity' if parms[:window] == Float::INFINITY
85
- @redis.set "parameters", parms.to_json
95
+ @redis.set "lsh:parameters", parms.to_json
86
96
  end
87
97
 
88
98
  def parameters
89
99
  begin
90
100
  @parms ||= (
91
- parms = JSON.parse(@redis.get "parameters")
101
+ parms = JSON.parse(@redis.get "lsh:parameters")
92
102
  parms.keys.each { |k| parms[k.to_sym] = parms[k]; parms.delete(k) }
93
103
  parms[:window] = Float::INFINITY if parms[:window] == 'Infinity'
94
104
  parms
@@ -99,7 +109,7 @@ module LSH
99
109
  end
100
110
 
101
111
  def create_new_bucket
102
- @redis.incr "buckets"
112
+ @redis.incr "lsh:buckets"
103
113
  end
104
114
 
105
115
  def add_vector_to_bucket(bucket, hash, vector)
@@ -108,14 +118,15 @@ module LSH
108
118
  end
109
119
 
110
120
  def find_bucket(i)
111
- "bucket:#{i}" if @redis.get("buckets").to_i > i
121
+ "lsh:bucket:#{i}"
112
122
  end
113
123
 
114
124
  def query_buckets(hashes)
115
125
  vector_hashes = []
116
126
  hashes.each_with_index do |hash, i|
117
127
  bucket = find_bucket(i)
118
- vector_hashes += @redis.smembers("#{bucket}:#{hash}")
128
+ results = @redis.smembers("#{bucket}:#{hash}")
129
+ vector_hashes += results if results
119
130
  end
120
131
  # Making sure we don't load the same vectors twice if they match
121
132
  # in different random projections
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lsh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: