Universal solution for working with any meaning
🚀 View Product Strategy & Solutions 📚 API Documentation
Install the package:
npm install @deep-foundation/deep
# or
yarn add @deep-foundation/deep
Import and use in your code:
// ESM
import { Deep } from '@deep-foundation/deep';
// CommonJS
const { Deep } = require('@deep-foundation/deep');
// Create a new Deep instance
const deep = new Deep();
You can interact with Deep through its CLI interface:
npx @deep-foundation/deep --cli
Once in the REPL session, you can explore and manipulate your Deep instance. Here's an example of finding and displaying all relations:
> const deep = new Deep()
> const allRelations = deep.select({})
> console.log(`Found ${allRelations.size} relations in total`)
>
> // Display relations grouped by type
> const byType = new Map()
> allRelations.each(rel => {
const type = rel.type?.value || 'untyped'
byType.set(type, (byType.get(type) || 0) + 1)
})
>
> console.log('\nRelations by type:')
> byType.forEach((count, type) => {
console.log(`${type}: ${count} relations`)
})
This will show you all relations in your Deep instance, organized by their types.
Deep is a universal system for representing and connecting any form of meaning - from basic data types to complex systems and behaviors. Just as our consciousness naturally associates different concepts, sensations, and ideas in a unified space, Deep creates a pure semantic space where everything is interconnected and accessible in a uniform way. It's designed to seamlessly handle any type of data or behavior - whether it's running code across different languages and platforms, managing distributed systems, or synchronizing with various data sources.
At its core, Deep aims to become a universal memory and perception system for both human and artificial intelligence. It provides AI systems with dynamic context mapping and intuitive navigation through semantic space, allowing any AI to perceive and operate on its designated memory region as if it were its own long-term and working memory. This unified approach to memory and perception enables seamless integration between different AI systems, letting them share and process information in a natural, context-aware manner.
In its visual incarnations across desktop, mobile platforms, and extensions, Deep provides a universal perception layer where the space itself and every element within it is an associative link to a React component. These components dynamically reflect various states of the associative memory, seamlessly integrating with Material-UI, Apache ECharts, and numerous other frameworks. This modular approach allows for complete visual customization without modifying the core engine - new visualization capabilities can be added simply by connecting additional dependencies, making Deep's visual representation as flexible as its underlying semantic structure.
Core Functionality:
- Universal associative graph data structure
- Uniform interface for all data types
- Reactive event system
- Complex querying with logical operators
- Event generation and applying
- Export Selection to JSON and import as Selection
- Transaction support
- Distributed computation support
Data Integration:
- File system watch/sync
- SQL databases sync
- MongoDB sync
- JSON import/export
- Custom data format adapters
Runtime and Execution:
- Multi-language code execution
- Process management
- Docker container integration
- Container orchestration
- Hierarchical behavior management
- State monitoring
API and Connectivity:
- HTTP API
- WebSocket support
- GraphQL interface
- Subscription system
- Access control and permissions
Platform Support:
- Node.js runtime
- Next.js web applications
- iOS (Capacitor)
- Android (Capacitor)
- Electron desktop
- Browser extensions
- IDE plugins
- Serverless functions
- Container deployments
AI Integration:
- Universal AI memory interface
- Long-term memory simulation
- Working memory allocation
- Memory region permissions
- Dynamic context mapping
- Real-time context updates
- Context inheritance
- Multi-dimensional context layers
- Semantic space navigation
- Natural language queries
- Semantic similarity search
- Contextual relevance scoring
- Memory region isolation and sharing
- Secure memory boundaries
- Controlled memory access
- Cross-region synchronization
- Multi-model perception layers
- Text understanding
- Image recognition
- Audio processing
- Multimodal fusion
- Standard AI protocols support
- LangChain integration
- AutoGPT compatibility
- Custom LLM integration
- Vector embeddings
- Neural network state persistence
- AI-to-AI communication protocols
- Semantic message passing
- Shared memory spaces
- Collaborative reasoning
- Context-aware memory allocation
- Dynamic memory scaling
- Priority-based allocation
- Resource optimization
- Intuitive memory visualization
- Interactive memory maps
- Relationship graphs
- Context hierarchies
- Real-time memory monitoring
The Deep class is the core of the system - it represents a universal agent capable of performing operations on any type of data. Each instance of Deep is an active agent that can interact with any other Deep instance or data type through a rich set of methods:
All methods work uniformly across different data types, treating single items as collections of one element where the item serves as both key and value. This approach allows for consistent data manipulation regardless of whether you're working with a single item or a collection.
has(item)
→ boolean - Checks if item exists in the collectionget(key)
→ value - Returns value by key, for single items the key is the item itselfset(key, value)
→ value - Sets value by key, returns the valueunset(key)
→ boolean - Removes value by key, returns success statusadd(value)
→ value - Adds value to collection, for single items replaces the valuesize()
→ number - Returns collection size, for single items returns 1 or 0keys()
→ Array - Returns array of keys, empty for single itemsvalues()
→ Array - Returns array of values, for single items returns array with one itemmap(callback(value, key))
→ Array - Maps over collection with callback, returns new arrayfind(callback(value, key))
→ any - Returns first item where callback returns truefilter(callback(value, key))
→ Array - Returns array of items where callback returns trueeach(callback(value, key))
→ void - Iterates over collection with callbackreduce(callback(accumulator, value), initial)
→ any - Reduces collection to single valuesort(callback(a, b))
→ Array - Returns sorted array based on callback comparisonfirst()
→ any - Returns first item of collection or the item itself for single itemslast()
→ any - Returns last item of collection or the item itself for single itemsjoin()
→ string - Converts collection to string, for single items calls toString()toString()
→ string - Returns string representationvalueOf()
→ any - Returns primitive value if possible
Examples
const A = deep.new();
const B = deep.new();
const C = deep.new();
const X = deep.new();
const a = A.new();
const b1 = B.new();
b1.from = a;
const c = C.new();
c.from = a;
const x = X.new();
const b2 = B.new();
b2.from = x;
// Search by specific relations
deep.select({ type: C }).to; // Deep<Set<[c]>>
// Search for links that referenced from B
deep.select({
out: { type: B }
}).to; // Deep<Set<[a,x]>>
// Get only those links from which both B and C instances originate at least one
deep.select({
and: [
{ out: { type: B } },
{ out: { type: C } },
]
}).to; // Deep<Set<[a]>>
select(expression)
→ Selection - Creates a reactive selection of links based on expression- Expression is an object that can contain the following keys, where each key's value can be either another expression object or a Deep instance:
- Direct selectors:
-
type
- Filter links by type -
from
- Filter links by source node -
to
- Filter links by target node -
id
- Filter links by id -
value
- Filter links by value
-
- Reverse selectors:
-
typed
- Filter links where they have this as their type -
out
- Filter links where they have this as their from -
in
- Filter links where they have this as their to -
valued
- Filter links where they have this as their value
-
- Logic operators:
-
not
- Exclude links matching the expression -
and
- Include links matching all expressions -
or
- Include links matching any expression (must be an array where each item can be an expression object or a Deep instance)
-
- Conditions (comparison operators):
-
eq
- Equal to -
neq
- Not equal to -
gt
- Greater than -
lt
- Less than -
gte
- Greater than or equal to -
lte
- Less than or equal to -
in
- Value is in array -
nin
- Value is not in array
-
- Direct selectors:
- Selection is reactive - automatically updates when matching links change
- Returns a Selection instance that contains matching links
- Examples:
// Direct (One to one) relations const linkType = someLink.type // returns Deep instance or undefined const linkFrom = someLink.from // returns Deep instance or undefined const linkTo = someLink.to // returns Deep instance or undefined const linkValue = someLink.value // returns Deep instance or JS primitive // Reverse (One to many) relations const linksOfThisType = someLink.typed.call() // get all links that use this as their type const linksFromThis = someLink.out.call() // get all links that start from this const linksToThis = someLink.in.call() // get all links that point to this const linksWithThisValue = someLink.valued.call() // get all links that have this as value // Complex query combining both types of relations const complexQuery = deep.select({ and: [ { type: someType }, // direct relation { not: { in: someTarget }}, // exclude links pointing to someTarget (reverse relation) { valued: someValue } // include links having someValue (reverse relation) ] }) complexQuery.call() // returns Deep instance with multiple results
- Expression is an object that can contain the following keys, where each key's value can be either another expression object or a Deep instance:
Selection is a special type of association that represents a dynamic query result. When created:
- It executes immediately once and stores the result in
selection.to
selection.to
always contains the latest query result- Calling
selection.call()
re-executes the query and updates the results - The selection automatically updates when the underlying data changes
insert({ type, from, to, value })
→ Deep - Creates new linkupdate({ type?, from?, to?, value? })
→ Deep - Updates existing linkdelete()
→ boolean - Removes link
Relations in Deep allow you to create complex interconnected structures. Here's an example with types A, B, C and their instances:
// Define types
const A = deep.new();
const B = deep.new();
const C = deep.new();
// Create instances
const a1 = A.new();
const b1 = B.new();
const c1 = C.new();
// (If we create a1,b1,c1 from deep.new(), not from A,B,C.new()), type can be setted manually:
// a1.type = A; // a1 is of type A
// b1.type = B; // b1 is of type B
// c1.type = C; // c1 is of type C
// Create relationships
a1.from = b1; // a1 points from b1
b1.to = c1; // b1 points to c1
c1.from = a1; // c1 points from a1
// Direct traversals
a1.type; // → A (get type of a1)
a1.from; // → b1 (get source node)
a1.to; // → undefined (no target node)
a1.typed; // → [a1] (get all instances of same type)
a1.out; // → [c1] (get all outgoing connections)
a1.in; // → [b1] (get all incoming connections)
// Multiple traversals
// You can chain traversals to navigate through the graph
a1.out; // → [c1] (get outgoing connections)
a1.out.tos; // → [] (get 'to' nodes of outgoing connections)
a1.out.froms; // → [a1] (get 'from' nodes of outgoing connections)
a1.out.types; // → [C] (get types of outgoing connections)
// Complex traversal example
// Get all nodes that are targets of our outgoing connections
// and then get their outgoing connections
a1.out.call.forEach(node => {
console.log(node.out.call); // show outgoing connections of each node
});
In this example:
- We have three types: A, B, C
- Instances a1, b1, c1 form a triangle of relationships
- We can traverse these relationships using direct properties (type, from, to, etc.)
- We can perform multiple traversals by chaining operations
- Each traversal returns a Deep instance that can be further queried
An association (link) consists of the following components:
- type - link type (also a Deep)
- from - link source (Deep)
- to - link target (Deep)
- value - link value (can be any data type)
When creating associations in Deep, there are several important patterns to understand:
When you create a new association using the .new()
method from an existing association:
- The association you're calling
.new()
from becomes the type of the new association - The optional argument passed to
.new()
becomes the value of the new association - For primitive JavaScript values (strings, numbers, booleans), the value is automatically wrapped in a special container for deduplication
Example:
const Type = deep.new();
const instance1 = Type.new('value1'); // Creates new association with Type as type and wrapped 'value1' as value
const instance2 = Type.new('value1'); // Reuses the same wrapped value due to deduplication
console.log(instance1.value); // Deep with .value == 'value1'
console.log(instance1.value === instance2.value); // true - same wrapped value reference
console.log(instance1.call, 'value1'); // true - возвращает конечное значение
This pattern enables:
- Type-safe association creation
- Automatic value deduplication
- Memory optimization for primitive values
- Consistent handling of values across the system
A key feature of Deep is its uniform approach to handling both single items and collections:
- When working with a single item, it's treated as a collection of one element where the item serves as both key and value
- The same methods work consistently across different data types (Symbol, Promise, Boolean, String, Number, BigInt, Set, Map, Array, Object, Function)
- This uniformity allows for seamless transitions between single and multiple data operations
- Creating new associations
- Modifying properties (type, from, to, value)
- Tracking changes through event system
- Iterating through links
- Searching links by various parameters
- Support for various .value types (Symbol, Promise, Boolean, String, Number, BigInt, Set, Map, Array, Object, Function)
- Event system
deep.on(event => {})
- Change observation
selection.on(event => {})
- Support for terminal (cli) web (NextJS) and native platforms (iOS, Android, Electron)
- TypeScript as the main language
- React for UI
- Next.js for server-side
- Cross-platform development support
- Event system for reactive programming
- Universality: can work with any data types
- Extensibility: ability to create custom link types
- Reactivity: automatic updates on changes
- Indexing: fast access to links through various indexes
- Cross-platform: works everywhere, from browser to mobile applications
This is free and unencumbered software released into the public domain under the Unlicense license.
For more information, please refer to the LICENSE file or visit https://unlicense.org.