I have a data structure like this in the database in the features table called `token_vector` (a hash):

```
Feature.find(1).token_vector = { "a" => 0.1, "b" => 0.2, "c" => 0.3 }

```

There are 25 of these features. First, I entered the data into Redis with this in `script/console`:

```
REDIS.set(  "feature1",
            "#{ TokenVector.to_json Feature.find(1).token_vector }"
)
# ...
REDIS.set(  "feature25",
            "#{ TokenVector.to_json Feature.find(25).token_vector }"
)

```

`TokenVector.to_json` converts the hash into JSON format first. The 25 JSON hashes stored in Redis take up about 8 MB.

I have a method, called `Analysis#locate`. This method takes the dot product between two token\_vectors. The dot product for hashes works like this:

```
hash1 = { "a" => 1, "b" => 2, "c" => 3 }
hash2 = { "a" => 4, "b" => 5, "c" => 6, "d" => 7 }

```

Each overlapping key in the hash (a, b, and c in this case, and not d) have their values multiplied pairwise together, then added up. 

The value for `a` in `hash1` is 1, the value for `a` in `hash2` is 4. Multiply these to get `1*4 = 4`.

The value for `b` in `hash1` is 2, the value for `b` in `hash2` is 5. Multiply these to get `2*5 = 10`.

The value for `c` in `hash1` is 3, the value for `c` in `hash2` is 6. Multiply these to get `3*6 = 18`.

The value for `d` in `hash1` is nonexistent, the value for `d` in `hash2` is 7. In this case, set `d = 0` for the first hash. Multiply these to get `0*7 = 0`.

Now add up the multiplied values. `4 + 10 + 18 + 0 = 32`. This is the dot product of hash1 and hash2.

```
Analysis.locate( hash1, hash2 ) # => 32

```

I have a method that is often used, `Analysis#topicize`. This method takes in a parameter, `token_vector`, which is just a hash, similar to above. `Analysis#topicize` takes the dot product of `token_vector` and each of the 25 features' `token_vectors`, and creates a new vector of those 25 dot products, called `feature_vector`. A `feature_vector` is just an array. Here is what the code looks like:

```
def self.topicize token_vector

  feature_vector = FeatureVector.new

  feature_vector.push(
    locate( token_vector, TokenVector.from_json( REDIS.get "feature1" ) )
  )
  # ...
  feature_vector.push(
    locate( token_vector, TokenVector.from_json( REDIS.get "feature25" ) )
  )

  feature_vector

end

```

As you can see, it takes the dot product of `token_vector` and each feature's `token_vector` that I entered into Redis above, and pushes the value into an array.

My problem is, this takes about 18 seconds each time I invoke the method. Am I misusing Redis? I think the problem could be that I shouldn't load Redis data into Ruby. Am I supposed to send Redis the data (`token_vector`) and write a Redis function to have it do the `dot_product` function, rather than writing it with Ruby code?