2026-02-19 17:04:05 -08:00
---
title: Triple Intelligence
slug: concepts/triple-intelligence
public: true
category: concepts
template: concept
order: 1
description: Unified vector similarity, graph traversal, and metadata filtering in one query. Auto-optimizes between parallel execution and progressive filtering.
next:
- concepts/noun-types
- api/reference
---
2025-08-26 12:32:21 -07:00
# Triple Intelligence System
The Triple Intelligence System is Brainy's revolutionary query engine that unifies vector similarity, graph relationships, and metadata filtering into a single, optimized query interface.
## Overview
Traditional databases force you to choose between vector search, graph traversal, OR metadata filtering. Brainy combines all three intelligences into one magical API that automatically optimizes execution for maximum performance.
## Query Interface
### Unified Query Structure
2026-06-29 10:03:02 -07:00
`find()` accepts a single `FindParams` object (or a natural-language string). One
object combines all three intelligences:
2025-08-26 12:32:21 -07:00
```typescript
2026-06-29 10:03:02 -07:00
interface FindParams {
// Vector intelligence — semantic similarity
query?: string // Natural-language / semantic query (embedded, matched via HNSW + text index)
vector?: number[] // Pre-computed embedding for direct vector search
// Metadata intelligence — structured field filters
type?: NounType | NounType[] // Filter by entity type
subtype?: string | string[] // Filter by per-product subtype
where?: Record< string , any > // Field predicates with bare operators (gte, lt, in, contains, exists…)
// Graph intelligence — relationship traversal
2025-08-26 12:32:21 -07:00
connected?: {
2026-06-29 10:03:02 -07:00
to?: string // Reachable to this entity
from?: string // Reachable from this entity
via?: VerbType | VerbType[] // Relationship type(s) to traverse (alias: type)
depth?: number // Max traversal depth (default: 1)
2025-08-26 12:32:21 -07:00
direction?: 'in' | 'out' | 'both'
}
2026-06-29 10:03:02 -07:00
// Proximity — nearest neighbours of a known entity
near?: { id: string; threshold?: number }
// Control
limit?: number // Max results (default: 10)
offset?: number // Skip N results
orderBy?: string // Field to sort by (e.g. 'createdAt')
order?: 'asc' | 'desc' // Sort direction
2025-08-26 12:32:21 -07:00
}
```
### Example Queries
#### Natural Language Queries with find()
```typescript
// Brainy understands natural language and extracts intent
const results = await brain.find("research papers about neural networks from 2023")
// Automatically interprets: document type, topic, time range
// Complex temporal and numeric queries
const reports = await brain.find("quarterly reports from Q3 2024 with revenue over 10M")
// Automatically extracts: report type, date range, numeric filters
// Multi-condition natural language
const articles = await brain.find("verified articles by John Smith about machine learning published this year")
// Automatically identifies: author, topic, verification status, time range
```
#### Simple Vector Search
```typescript
feat(8.0): API simplification — remove neural()/Db.search, one storage `path` key, integration→0
8.0 RC cleanup toward "one place per thing, zero-config, no deprecation":
- Remove the `brain.neural()` clustering namespace (ImprovedNeuralAPI + the dead
legacy NeuralAPI + the neural CLI + neural-only types). Similarity is `find({vector})`
/ `similar({to})`; attribute grouping is the aggregation `GROUP BY` engine. The separate
entity-extraction / smart-import feature (NeuralImport, NeuralEntityExtractor, SmartExtractor,
NaturalLanguageProcessor, `brain.extract()`/`brain.nlp()`) is kept.
- Remove `Db.search()`; `find()` is the one query verb (accepts a bare string or FindParams).
Fix the bundled MCP client, which called a non-existent `brain.search(query, limit)` →
now `find({ query, limit })`.
- Storage config: collapse to one canonical top-level `path` key. The pre-8.0 aliases
(`rootDirectory`, `options.*`, `fileSystemStorage.*`) are removed and now THROW with the
exact rename instead of silently defaulting to `./brainy-data` on upgrade. A single resolver
feeds createStorage, the 7.x→8.0 migration probe, and the plugin-factory handoff, so a native
storage provider resolves the identical root (no split-brain).
- Fix `similar({ threshold })`: the min-similarity filter was silently dropped; it is now
applied as a post-filter on `result.score` (the documented way to bound semantic results).
- Fix `vfs.rename()` on a directory: child path updates spread the entity vector into `update()`
and failed dimension validation; they are metadata-only updates now.
- Fix `vfs.move()`: copy+delete orphaned the content-addressed content blob (the destination
shared the source hash, then unlink removed it). `move()` now delegates to `rename()` — an
in-place path change that preserves the blob and the entity id, for files and directories.
- Fix streaming import: the bulk fast path never flushed mid-import nor signalled queryability.
Entity writes are now chunked by a progressive flush interval (100 → 1000 → 5000); each chunk
flushes and emits `progress.queryable`, so imported data is queryable during the import.
- Sweep all docs, comments, and JSDoc for the removed/changed APIs.
Integration suite: 49 files / 588 passed / 0 failed. Unit: 80 files / 1456 passed, no type errors.
2026-06-20 13:31:11 -07:00
const results = await brain.find("machine learning concepts")
2025-08-26 12:32:21 -07:00
```
#### Combined Intelligence Query
```typescript
const results = await brain.find({
2026-06-29 10:03:02 -07:00
query: "neural networks",
2025-08-26 12:32:21 -07:00
where: {
category: "research",
2026-06-29 10:03:02 -07:00
year: { gte: 2023 }
2025-08-26 12:32:21 -07:00
},
connected: {
to: "deep-learning-team",
depth: 2
},
limit: 20
})
```
## Query Optimization
### Automatic Plan Generation
The Triple Intelligence engine analyzes each query to create an optimal execution plan:
1. **Selectivity Analysis** : Identifies the most selective filters
2. **Cost Estimation** : Estimates computational cost for each operation
3. **Strategy Selection** : Chooses between parallel or progressive execution
4. **Plan Caching** : Caches successful plans for similar queries
### Execution Strategies
#### Parallel Execution
All three search types execute simultaneously:
- **Best for**: Balanced queries with multiple signals
- **Performance**: Maximum speed through parallelization
- **Use case**: Complex queries needing all intelligence types
```typescript
// Parallel execution for balanced query
const results = await brain.find({
2026-06-29 10:03:02 -07:00
query: "AI research", // ~1000 potential matches
where: { kind: "paper" }, // ~500 potential matches
2025-08-26 12:32:21 -07:00
connected: { to: "stanford" } // ~200 potential matches
})
// All three execute in parallel, results fused
```
#### Progressive Filtering
Operations chain for maximum efficiency:
- **Best for**: Queries with highly selective filters
- **Performance**: Reduces search space at each step
- **Use case**: Large datasets with specific criteria
```typescript
// Progressive execution for selective query
const results = await brain.find({
where: { userId: "user123" }, // Very selective (1-10 matches)
2026-06-29 10:03:02 -07:00
query: "recent posts", // Applied to filtered set
2025-08-26 12:32:21 -07:00
limit: 5
})
// Metadata filter first, then vector search on results
```
## Fusion Ranking
### Score Combination
When multiple intelligence types return results, scores are intelligently combined:
```typescript
fusionScore = (
vectorScore * vectorWeight + // Semantic relevance (0.4)
graphScore * graphWeight + // Relationship strength (0.3)
fieldScore * fieldWeight // Exact match confidence (0.3)
) / totalWeight
```
### Adaptive Weights
Weights adjust based on query characteristics:
- **Text-heavy query**: Higher vector weight
- **Relationship query**: Higher graph weight
- **Specific filters**: Higher field weight
## Natural Language Processing
### Pattern Recognition
Brainy includes 220+ embedded patterns for natural language understanding:
```typescript
// Natural language automatically parsed
feat(8.0): API simplification — remove neural()/Db.search, one storage `path` key, integration→0
8.0 RC cleanup toward "one place per thing, zero-config, no deprecation":
- Remove the `brain.neural()` clustering namespace (ImprovedNeuralAPI + the dead
legacy NeuralAPI + the neural CLI + neural-only types). Similarity is `find({vector})`
/ `similar({to})`; attribute grouping is the aggregation `GROUP BY` engine. The separate
entity-extraction / smart-import feature (NeuralImport, NeuralEntityExtractor, SmartExtractor,
NaturalLanguageProcessor, `brain.extract()`/`brain.nlp()`) is kept.
- Remove `Db.search()`; `find()` is the one query verb (accepts a bare string or FindParams).
Fix the bundled MCP client, which called a non-existent `brain.search(query, limit)` →
now `find({ query, limit })`.
- Storage config: collapse to one canonical top-level `path` key. The pre-8.0 aliases
(`rootDirectory`, `options.*`, `fileSystemStorage.*`) are removed and now THROW with the
exact rename instead of silently defaulting to `./brainy-data` on upgrade. A single resolver
feeds createStorage, the 7.x→8.0 migration probe, and the plugin-factory handoff, so a native
storage provider resolves the identical root (no split-brain).
- Fix `similar({ threshold })`: the min-similarity filter was silently dropped; it is now
applied as a post-filter on `result.score` (the documented way to bound semantic results).
- Fix `vfs.rename()` on a directory: child path updates spread the entity vector into `update()`
and failed dimension validation; they are metadata-only updates now.
- Fix `vfs.move()`: copy+delete orphaned the content-addressed content blob (the destination
shared the source hash, then unlink removed it). `move()` now delegates to `rename()` — an
in-place path change that preserves the blob and the entity id, for files and directories.
- Fix streaming import: the bulk fast path never flushed mid-import nor signalled queryability.
Entity writes are now chunked by a progressive flush interval (100 → 1000 → 5000); each chunk
flushes and emits `progress.queryable`, so imported data is queryable during the import.
- Sweep all docs, comments, and JSDoc for the removed/changed APIs.
Integration suite: 49 files / 588 passed / 0 failed. Unit: 80 files / 1456 passed, no type errors.
2026-06-20 13:31:11 -07:00
const results = await brain.find(
2025-08-26 12:32:21 -07:00
"show me recent AI papers from Stanford published this year"
)
// Automatically converts to:
// {
2026-06-29 10:03:02 -07:00
// query: "AI papers",
// where: {
2025-08-26 12:32:21 -07:00
// institution: "Stanford",
2026-06-29 10:03:02 -07:00
// published: { gte: "2024-01-01" }
2025-08-26 12:32:21 -07:00
// }
// }
```
### Intent Detection
The NLP processor identifies query intent:
- **Informational**: "what is", "how does"
- **Navigational**: "find", "show me"
- **Transactional**: "create", "update"
- **Analytical**: "compare", "analyze"
## Performance Optimization
### Query Plan Caching
Successful execution plans are cached:
```typescript
2026-06-29 10:03:02 -07:00
// First call parses the natural-language query and builds an execution plan
feat(8.0): API simplification — remove neural()/Db.search, one storage `path` key, integration→0
8.0 RC cleanup toward "one place per thing, zero-config, no deprecation":
- Remove the `brain.neural()` clustering namespace (ImprovedNeuralAPI + the dead
legacy NeuralAPI + the neural CLI + neural-only types). Similarity is `find({vector})`
/ `similar({to})`; attribute grouping is the aggregation `GROUP BY` engine. The separate
entity-extraction / smart-import feature (NeuralImport, NeuralEntityExtractor, SmartExtractor,
NaturalLanguageProcessor, `brain.extract()`/`brain.nlp()`) is kept.
- Remove `Db.search()`; `find()` is the one query verb (accepts a bare string or FindParams).
Fix the bundled MCP client, which called a non-existent `brain.search(query, limit)` →
now `find({ query, limit })`.
- Storage config: collapse to one canonical top-level `path` key. The pre-8.0 aliases
(`rootDirectory`, `options.*`, `fileSystemStorage.*`) are removed and now THROW with the
exact rename instead of silently defaulting to `./brainy-data` on upgrade. A single resolver
feeds createStorage, the 7.x→8.0 migration probe, and the plugin-factory handoff, so a native
storage provider resolves the identical root (no split-brain).
- Fix `similar({ threshold })`: the min-similarity filter was silently dropped; it is now
applied as a post-filter on `result.score` (the documented way to bound semantic results).
- Fix `vfs.rename()` on a directory: child path updates spread the entity vector into `update()`
and failed dimension validation; they are metadata-only updates now.
- Fix `vfs.move()`: copy+delete orphaned the content-addressed content blob (the destination
shared the source hash, then unlink removed it). `move()` now delegates to `rename()` — an
in-place path change that preserves the blob and the entity id, for files and directories.
- Fix streaming import: the bulk fast path never flushed mid-import nor signalled queryability.
Entity writes are now chunked by a progressive flush interval (100 → 1000 → 5000); each chunk
flushes and emits `progress.queryable`, so imported data is queryable during the import.
- Sweep all docs, comments, and JSDoc for the removed/changed APIs.
Integration suite: 49 files / 588 passed / 0 failed. Unit: 80 files / 1456 passed, no type errors.
2026-06-20 13:31:11 -07:00
await brain.find("machine learning papers")
2025-08-26 12:32:21 -07:00
2026-06-29 10:03:02 -07:00
// A structurally similar query reuses that plan, skipping plan generation
feat(8.0): API simplification — remove neural()/Db.search, one storage `path` key, integration→0
8.0 RC cleanup toward "one place per thing, zero-config, no deprecation":
- Remove the `brain.neural()` clustering namespace (ImprovedNeuralAPI + the dead
legacy NeuralAPI + the neural CLI + neural-only types). Similarity is `find({vector})`
/ `similar({to})`; attribute grouping is the aggregation `GROUP BY` engine. The separate
entity-extraction / smart-import feature (NeuralImport, NeuralEntityExtractor, SmartExtractor,
NaturalLanguageProcessor, `brain.extract()`/`brain.nlp()`) is kept.
- Remove `Db.search()`; `find()` is the one query verb (accepts a bare string or FindParams).
Fix the bundled MCP client, which called a non-existent `brain.search(query, limit)` →
now `find({ query, limit })`.
- Storage config: collapse to one canonical top-level `path` key. The pre-8.0 aliases
(`rootDirectory`, `options.*`, `fileSystemStorage.*`) are removed and now THROW with the
exact rename instead of silently defaulting to `./brainy-data` on upgrade. A single resolver
feeds createStorage, the 7.x→8.0 migration probe, and the plugin-factory handoff, so a native
storage provider resolves the identical root (no split-brain).
- Fix `similar({ threshold })`: the min-similarity filter was silently dropped; it is now
applied as a post-filter on `result.score` (the documented way to bound semantic results).
- Fix `vfs.rename()` on a directory: child path updates spread the entity vector into `update()`
and failed dimension validation; they are metadata-only updates now.
- Fix `vfs.move()`: copy+delete orphaned the content-addressed content blob (the destination
shared the source hash, then unlink removed it). `move()` now delegates to `rename()` — an
in-place path change that preserves the blob and the entity id, for files and directories.
- Fix streaming import: the bulk fast path never flushed mid-import nor signalled queryability.
Entity writes are now chunked by a progressive flush interval (100 → 1000 → 5000); each chunk
flushes and emits `progress.queryable`, so imported data is queryable during the import.
- Sweep all docs, comments, and JSDoc for the removed/changed APIs.
Integration suite: 49 files / 588 passed / 0 failed. Unit: 80 files / 1456 passed, no type errors.
2026-06-20 13:31:11 -07:00
await brain.find("deep learning papers")
2025-08-26 12:32:21 -07:00
```
### Self-Optimization
Brainy uses itself to optimize queries:
- Query patterns stored in separate brain instance
- Execution times tracked and analyzed
- Plans automatically improved based on performance
### Index Utilization
Triple Intelligence leverages all available indexes:
- **HNSW Index**: For vector similarity
- **Metadata Index**: For metadata filtering
- **Graph Index**: For relationship traversal
## Advanced Features
### Explain Mode
2026-06-29 10:03:02 -07:00
Diagnose how a query's `where` fields map to the index. Run `brain.explain()`
first whenever `find()` returns surprising or empty results:
2025-08-26 12:32:21 -07:00
```typescript
2026-06-29 10:03:02 -07:00
const plan = await brain.explain({
query: "quantum computing",
where: { category: "research" }
2025-08-26 12:32:21 -07:00
})
2026-06-29 10:03:02 -07:00
console.log(plan.fieldPlan)
// [
// { field: 'category', path: 'column-store', notes: '...' }
// ]
console.log(plan.warnings)
// e.g. ['Field "category" has no index entries. find() will return [] silently...']
2025-08-26 12:32:21 -07:00
```
2026-06-29 10:03:02 -07:00
### Result Ordering
2025-08-26 12:32:21 -07:00
2026-06-29 10:03:02 -07:00
Sort results by any stored field with `orderBy` / `order` :
2025-08-26 12:32:21 -07:00
```typescript
const results = await brain.find({
2026-06-29 10:03:02 -07:00
query: "news articles",
where: { verified: true },
orderBy: 'createdAt', // Newest first
order: 'desc'
2025-08-26 12:32:21 -07:00
})
```
2026-06-29 10:03:02 -07:00
### Similarity Threshold
2025-08-26 12:32:21 -07:00
2026-06-29 10:03:02 -07:00
Find the nearest neighbours of a known entity and keep only close matches with
`near` :
2025-08-26 12:32:21 -07:00
```typescript
const results = await brain.find({
2026-06-29 10:03:02 -07:00
near: { id: anchorId, threshold: 0.9 }, // Only results >= 0.9 similarity
2025-08-26 12:32:21 -07:00
limit: 10
})
```
## Best Practices
### Query Design
1. **Start specific** : Use selective filters when possible
2. **Combine intelligently** : Don't force all three types if not needed
3. **Use limits** : Always specify reasonable result limits
4. **Cache results** : For repeated queries, cache at application level
### Performance Tips
1. **Index first** : Ensure fields used in `where` clauses are indexed
2. **Batch operations** : Use batch methods for bulk queries
3. **Monitor plans** : Use explain mode to understand performance
4. **Optimize patterns** : Train custom patterns for your domain
### Common Patterns
#### Semantic Search with Filtering
```typescript
// Find similar content with constraints
const results = await brain.find({
2026-06-29 10:03:02 -07:00
query: searchText,
where: {
2025-08-26 12:32:21 -07:00
status: 'published',
language: 'en'
}
})
```
#### Related Items Discovery
```typescript
// Find items related to a specific item
const results = await brain.find({
2026-06-29 10:03:02 -07:00
connected: {
2025-08-26 12:32:21 -07:00
to: itemId,
depth: 2,
2026-06-29 10:03:02 -07:00
via: VerbType.RelatedTo
2025-08-26 12:32:21 -07:00
},
limit: 20
})
```
#### Time-based Queries
```typescript
// Recent items matching criteria
const results = await brain.find({
where: {
2026-06-29 10:03:02 -07:00
timestamp: { gte: Date.now() - 86400000 }
2025-08-26 12:32:21 -07:00
},
2026-06-29 10:03:02 -07:00
query: "trending topics",
orderBy: 'timestamp',
order: 'desc'
2025-08-26 12:32:21 -07:00
})
```
## Natural Language Processing
The `find()` method includes advanced NLP capabilities powered by 220+ embedded patterns that understand natural language queries.
### Supported Query Types
```typescript
// Temporal queries
await brain.find("documents from last week")
await brain.find("reports created yesterday")
await brain.find("articles published in Q3 2024")
await brain.find("data from January to March")
// Numeric filters
await brain.find("products with price under $100")
await brain.find("articles with more than 1000 views")
await brain.find("reports showing revenue over 10M")
// Combined conditions
await brain.find("verified research papers about AI from 2024 with high citations")
await brain.find("recent customer reviews with rating above 4 stars")
await brain.find("blog posts by John Smith about machine learning published this month")
// Relationship queries
await brain.find("documents related to project X")
await brain.find("people who work at TechCorp")
await brain.find("products similar to iPhone")
```
### How It Works
1. **Intent Detection** : Identifies what the user is looking for
2. **Entity Extraction** : Extracts names, dates, numbers, categories
3. **Temporal Parsing** : Converts "last week", "Q3 2024" to date ranges
4. **Filter Generation** : Creates appropriate where clauses
5. **Query Fusion** : Combines NLP understanding with vector search
### Pattern Coverage
Brainy includes 220+ pre-computed patterns covering:
- **Temporal**: 40+ patterns for dates and time ranges
- **Numeric**: 30+ patterns for comparisons and ranges
- **Relationships**: 25+ patterns for connections
- **Actions**: 35+ patterns for verbs and intents
- **Entities**: 40+ patterns for people, places, things
- **Domain-specific**: 50+ patterns for tech, business, social
## API Reference
See the [Triple Intelligence API ](../api/triple-intelligence.md ) for complete method documentation.