55 lines
2.0 KiB
EmacsLisp
55 lines
2.0 KiB
EmacsLisp
// activate.el — The `activate` construct: spreading activation over the type graph.
|
|
//
|
|
// The `activate` keyword is the most novel feature of the Engram language.
|
|
// Instead of querying a database with SQL or a key lookup, you query the
|
|
// *type graph* using a natural language description. The result is
|
|
// statically typed — the compiler knows you get [User] back, not Any.
|
|
//
|
|
// How it works:
|
|
//
|
|
// 1. At compile time, the type checker verifies that `User` is a registered
|
|
// type with a corresponding Engram node mapping.
|
|
//
|
|
// 2. At runtime, the Engram runtime performs spreading activation over
|
|
// the knowledge graph, starting from the User node, propagating to
|
|
// semantically related nodes with co-activation energy proportional
|
|
// to edge weights and node salience.
|
|
//
|
|
// 3. The query string "customer who purchased recently" is embedded
|
|
// and used as a semantic filter: only nodes whose embeddings are
|
|
// within cosine-similarity threshold of the query embedding are returned.
|
|
//
|
|
// 4. The result is type-safe: [User]. You don't get back Any or a JSON blob.
|
|
// The type checker enforces this at compile time.
|
|
|
|
type User {
|
|
id: Uuid
|
|
name: String
|
|
email: String
|
|
}
|
|
|
|
type Order {
|
|
id: Uuid
|
|
user_id: Uuid
|
|
amount: Float
|
|
status: String
|
|
}
|
|
|
|
// Query: find all users who are semantically related to "customer who purchased recently"
|
|
// The result type is [User] — an array of User nodes from the knowledge graph.
|
|
let recent_buyers: [User] = activate User where "customer who purchased recently"
|
|
|
|
// You can also activate on other types:
|
|
let pending_orders: [Order] = activate Order where "order awaiting fulfillment"
|
|
|
|
// Spreading activation respects the type graph edges.
|
|
// If User and Customer share an Engram node type (e.g. "Entity"),
|
|
// they are semantically compatible — the type checker allows
|
|
// treating one as the other when they map to the same Engram node class.
|
|
|
|
fn process_buyers(users: [User]) -> String {
|
|
return "processing users"
|
|
}
|
|
|
|
let result: String = process_buyers(recent_buyers)
|