Class: CreateLlmemoryTables

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/llmemory/install/templates/create_llmemory_tables.rb

Instance Method Summary collapse

Instance Method Details

#changeObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/generators/llmemory/install/templates/create_llmemory_tables.rb', line 4

def change
  create_table :llmemory_resources, id: false do |t|
    t.string :id, null: false, primary_key: true
    t.string :user_id, null: false
    t.text :text, null: false
    t.timestamps
  end
  add_index :llmemory_resources, :user_id

  create_table :llmemory_items, id: false do |t|
    t.string :id, null: false, primary_key: true
    t.string :user_id, null: false
    t.string :category, null: false
    t.text :content, null: false
    t.string :source_resource_id
    t.float :importance, default: 0.7
    t.jsonb :provenance
    t.timestamps
  end
  add_index :llmemory_items, :user_id

  create_table :llmemory_categories do |t|
    t.string :user_id, null: false
    t.string :category_name, null: false
    t.text :content, null: false
    t.datetime :updated_at, null: false
  end
  add_index :llmemory_categories, [:user_id, :category_name], unique: true

  create_table :llmemory_checkpoints do |t|
    t.string :user_id, null: false
    t.string :session_id, null: false
    t.jsonb :state, null: false, default: {}
    t.timestamps
  end
  add_index :llmemory_checkpoints, [:user_id, :session_id], unique: true

  # Graph-based long-term memory (nodes = entities)
  create_table :llmemory_nodes do |t|
    t.string :user_id, null: false
    t.string :entity_type, null: false
    t.string :name, null: false
    t.jsonb :properties, default: {}
    t.timestamps
  end
  add_index :llmemory_nodes, [:user_id, :entity_type, :name], unique: true

  # Graph-based long-term memory (edges = SPO relations)
  create_table :llmemory_edges do |t|
    t.string :user_id, null: false
    t.references :subject, null: false, foreign_key: { to_table: :llmemory_nodes }
    t.string :predicate, null: false
    t.references :object, null: false, foreign_key: { to_table: :llmemory_nodes }
    t.jsonb :properties, default: {}
    t.datetime :archived_at
    t.timestamps
  end
  add_index :llmemory_edges, [:user_id, :subject_id, :predicate]

  # Vector store for hybrid retrieval (requires pgvector extension)
  enable_extension "vector"
  create_table :llmemory_embeddings do |t|
    t.string :user_id, null: false
    t.string :source_type, null: false
    t.string :source_id, null: false
    t.vector :embedding, limit: 1536
    t.text :text_content
    t.timestamps
  end
  add_index :llmemory_embeddings, [:user_id, :source_type, :source_id], unique: true
end