-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduckdb_full.exs
More file actions
55 lines (44 loc) · 1.33 KB
/
duckdb_full.exs
File metadata and controls
55 lines (44 loc) · 1.33 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
# DuckDB Memory Store
#
# Uses DuckDB with FTS and vector similarity search.
# Requires: {:duckdbex, "~> 0.3"}
#
# Run: mix run examples/memory/duckdb_full.exs
alias Nous.Memory.{Entry, Store, Search}
db_path = Path.join(System.tmp_dir!(), "nous_memory_example.duckdb")
File.rm(db_path)
IO.puts("Opening DuckDB database at #{db_path}")
{:ok, store} = Store.DuckDB.init(path: db_path)
# Store memories
entries = [
Entry.new(%{content: "The user's name is Alice", importance: 0.9}),
Entry.new(%{content: "Alice works at Acme Corp on the data team", importance: 0.8}),
Entry.new(%{
content: "Preferred communication style: concise and technical",
importance: 0.7,
evergreen: true
}),
Entry.new(%{
content: "Last discussed topic: Elixir GenServer patterns",
importance: 0.5,
type: :episodic
})
]
store =
Enum.reduce(entries, store, fn entry, s ->
{:ok, s} = Store.DuckDB.store(s, entry)
s
end)
IO.puts("Stored #{length(entries)} memories\n")
# Search
queries = ["Who is the user?", "communication preferences", "what did we discuss?"]
for query <- queries do
{:ok, results} = Search.search(Store.DuckDB, store, query)
IO.puts("Query: \"#{query}\"")
for {entry, score} <- results do
IO.puts(" [#{Float.round(score, 3)}] #{entry.content}")
end
IO.puts("")
end
File.rm(db_path)
IO.puts("Done!")