Method: LlmMemory::RedisStore#create_index

Defined in:
lib/llm_memory/stores/redis_store.rb

#create_index(dim: 1536, distance_metric: "COSINE") ⇒ Object

dimention: 1536 for ada-002


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/llm_memory/stores/redis_store.rb', line 51

def create_index(dim: 1536, distance_metric: "COSINE")
  # LangChain index
  # schema = (
  #   TextField(name=content_key),
  #   TextField(name=metadata_key),
  #   VectorField(
  #       vector_key,
  #       "FLAT",
  #       {
  #           "TYPE": "FLOAT32",
  #           "DIM": dim,
  #           "DISTANCE_METRIC": distance_metric,
  #       },
  #   ),
  # )
  command = [
    "FT.CREATE", @index_name, "ON", "HASH",
    "PREFIX", "1", "#{@index_name}:",
    "SCHEMA",
    @content_key, "TEXT",
    @metadata_key, "TEXT",
    @vector_key, "VECTOR", "FLAT", 6, "TYPE", "FLOAT32", "DIM", dim, "DISTANCE_METRIC", distance_metric
  ]
  @client.call(command)
end