-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlite_full.exs
More file actions
72 lines (60 loc) · 1.72 KB
/
sqlite_full.exs
File metadata and controls
72 lines (60 loc) · 1.72 KB
1
2
3
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
# SQLite Memory Store
#
# Uses SQLite with FTS5 for full-text search. Single file, embedded database.
# Requires: {:exqlite, "~> 0.27"}
#
# Run: mix run examples/memory/sqlite_full.exs
alias Nous.Memory.{Entry, Store, Search}
db_path = Path.join(System.tmp_dir!(), "nous_memory_example.db")
# Start fresh
File.rm(db_path)
IO.puts("Opening SQLite database at #{db_path}")
{:ok, store} = Store.SQLite.init(path: db_path)
# Store memories
entries = [
Entry.new(%{
content: "User prefers dark mode in VS Code",
importance: 0.8,
agent_id: "assistant"
}),
Entry.new(%{
content: "Project deadline is March 15th",
importance: 0.9,
type: :episodic,
agent_id: "assistant"
}),
Entry.new(%{
content: "Use mix format before committing",
importance: 0.7,
type: :procedural,
evergreen: true,
agent_id: "assistant"
}),
Entry.new(%{
content: "The API rate limit is 100 requests per minute",
importance: 0.6,
agent_id: "researcher"
})
]
store =
Enum.reduce(entries, store, fn entry, s ->
{:ok, s} = Store.SQLite.store(s, entry)
s
end)
IO.puts("Stored #{length(entries)} memories\n")
# Text search (uses FTS5 BM25)
{:ok, results} = Search.search(Store.SQLite, store, "dark mode")
IO.puts("Search: 'dark mode'")
for {entry, score} <- results do
IO.puts(" [#{Float.round(score, 3)}] #{entry.content}")
end
# Scoped search — only assistant's memories
IO.puts("\nScoped search (agent_id: assistant): 'deadline'")
{:ok, results} =
Search.search(Store.SQLite, store, "deadline", nil, scope: %{agent_id: "assistant"})
for {entry, score} <- results do
IO.puts(" [#{Float.round(score, 3)}] #{entry.content}")
end
# Clean up
File.rm(db_path)
IO.puts("\nDone! Database cleaned up.")