-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmulti_backend.mnm
More file actions
65 lines (57 loc) · 1.36 KB
/
multi_backend.mnm
File metadata and controls
65 lines (57 loc) · 1.36 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
# multi_backend.mnm
# Multi-backend memory system with aliased query scoring
config {
storage: sqlite("./data/multi.db")
vector: {
primary: auto("qdrant"),
fast: auto("chromadb")
}
graph: {
kg: auto("neo4j"),
social: auto("memgraph")
}
embedding: openai("text-embedding-3-small")
extractor: openai("gpt-4o-mini")
}
namespace multi_agent {
memory Knowledge {
content: string
subject: string
predicate: string
object: string
confidence: float[0,1]
source: string?
created_at: timestamp
@index subject
@index predicate
}
on ingest(content: string) {
content
|> extract()
|> store()
}
# Query using aliased scores for custom ranking
query Search(input: string): Knowledge[] {
from Knowledge
where semantic_match(input, backend: "primary", threshold: 0.5) as sm
and graph_match(input, backend: "kg", hops: 2) as gm
order by sm * 0.6 + gm * 0.4 desc
limit 20
}
# Query with pure semantic match on a specific backend
query FastSearch(input: string): Knowledge[] {
from Knowledge
where semantic_match(input, backend: "fast", threshold: 0.7) as score
order by score desc
limit 10
}
update Knowledge {
on_conflict(old, new) {
if new.confidence > old.confidence {
supersede(old, new)
} else {
discard(new)
}
}
}
}