docs: convert code examples to TypeScript
All code examples in installation.md and quick-start.md were tagged as javascript — converted to typescript throughout. quick-start.md also gets explicit type annotations: - reactId/nextId declared as string (return type of brain.add) - results declared as FindResult[] - results[0].data and results[0].score shown in console.log example
This commit is contained in:
parent
fae88d0fdd
commit
791cacc6c0
2 changed files with 15 additions and 13 deletions
|
|
@ -34,7 +34,7 @@ pnpm add @soulcraft/brainy
|
||||||
|
|
||||||
## Verify
|
## Verify
|
||||||
|
|
||||||
```javascript
|
```typescript
|
||||||
import { Brainy } from '@soulcraft/brainy'
|
import { Brainy } from '@soulcraft/brainy'
|
||||||
|
|
||||||
const brain = new Brainy()
|
const brain = new Brainy()
|
||||||
|
|
@ -51,7 +51,7 @@ For production workloads, add Cortex for Rust-accelerated SIMD distance calculat
|
||||||
npm install @soulcraft/cortex
|
npm install @soulcraft/cortex
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript
|
```typescript
|
||||||
import { Brainy } from '@soulcraft/brainy'
|
import { Brainy } from '@soulcraft/brainy'
|
||||||
import { registerCortex } from '@soulcraft/cortex'
|
import { registerCortex } from '@soulcraft/cortex'
|
||||||
|
|
||||||
|
|
@ -67,7 +67,7 @@ Cortex delivers a **5.2x geometric mean speedup** — see [Brainy vs Cortex](/do
|
||||||
|
|
||||||
Brainy works in the browser using the Origin Private File System:
|
Brainy works in the browser using the Origin Private File System:
|
||||||
|
|
||||||
```javascript
|
```typescript
|
||||||
import { Brainy } from '@soulcraft/brainy'
|
import { Brainy } from '@soulcraft/brainy'
|
||||||
|
|
||||||
const brain = new Brainy({ storage: 'opfs' })
|
const brain = new Brainy({ storage: 'opfs' })
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ npm install @soulcraft/brainy
|
||||||
|
|
||||||
## 2. Initialize
|
## 2. Initialize
|
||||||
|
|
||||||
```javascript
|
```typescript
|
||||||
import { Brainy, NounType, VerbType } from '@soulcraft/brainy'
|
import { Brainy, NounType, VerbType } from '@soulcraft/brainy'
|
||||||
|
|
||||||
const brain = new Brainy()
|
const brain = new Brainy()
|
||||||
|
|
@ -34,15 +34,15 @@ That's it. Brainy auto-configures storage, loads the embedding model, and builds
|
||||||
|
|
||||||
## 3. Add Knowledge
|
## 3. Add Knowledge
|
||||||
|
|
||||||
```javascript
|
```typescript
|
||||||
// Text is automatically embedded into 384-dim vectors
|
// Text is automatically embedded into 384-dim vectors
|
||||||
const reactId = await brain.add({
|
const reactId: string = await brain.add({
|
||||||
data: 'React is a JavaScript library for building user interfaces',
|
data: 'React is a JavaScript library for building user interfaces',
|
||||||
type: NounType.Concept,
|
type: NounType.Concept,
|
||||||
metadata: { category: 'frontend', year: 2013 }
|
metadata: { category: 'frontend', year: 2013 }
|
||||||
})
|
})
|
||||||
|
|
||||||
const nextId = await brain.add({
|
const nextId: string = await brain.add({
|
||||||
data: 'Next.js framework for React with server-side rendering',
|
data: 'Next.js framework for React with server-side rendering',
|
||||||
type: NounType.Concept,
|
type: NounType.Concept,
|
||||||
metadata: { category: 'framework', year: 2016 }
|
metadata: { category: 'framework', year: 2016 }
|
||||||
|
|
@ -51,7 +51,7 @@ const nextId = await brain.add({
|
||||||
|
|
||||||
## 4. Create Relationships
|
## 4. Create Relationships
|
||||||
|
|
||||||
```javascript
|
```typescript
|
||||||
// Typed graph relationships
|
// Typed graph relationships
|
||||||
await brain.relate({
|
await brain.relate({
|
||||||
from: nextId,
|
from: nextId,
|
||||||
|
|
@ -62,16 +62,18 @@ await brain.relate({
|
||||||
|
|
||||||
## 5. Query with Triple Intelligence
|
## 5. Query with Triple Intelligence
|
||||||
|
|
||||||
```javascript
|
```typescript
|
||||||
|
import type { FindResult } from '@soulcraft/brainy'
|
||||||
|
|
||||||
// All three search paradigms in one call
|
// All three search paradigms in one call
|
||||||
const results = await brain.find({
|
const results: FindResult[] = await brain.find({
|
||||||
query: 'modern frontend frameworks', // Vector similarity search
|
query: 'modern frontend frameworks', // Vector similarity search
|
||||||
where: { year: { greaterThan: 2015 } }, // Metadata filtering
|
where: { year: { greaterThan: 2015 } }, // Metadata filtering
|
||||||
connected: { to: reactId, depth: 2 } // Graph traversal
|
connected: { to: reactId, depth: 2 } // Graph traversal
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(results.items)
|
console.log(results[0].data) // 'Next.js framework for React...'
|
||||||
// [{ id: nextId, data: 'Next.js...', score: 0.94, ... }]
|
console.log(results[0].score) // 0.94
|
||||||
```
|
```
|
||||||
|
|
||||||
## What Just Happened
|
## What Just Happened
|
||||||
|
|
@ -90,7 +92,7 @@ Every entity you `add()` lives in three indexes simultaneously:
|
||||||
|
|
||||||
Brainy understands 220+ natural language patterns:
|
Brainy understands 220+ natural language patterns:
|
||||||
|
|
||||||
```javascript
|
```typescript
|
||||||
// These all work without any configuration
|
// These all work without any configuration
|
||||||
await brain.find({ query: 'recent documents about machine learning' })
|
await brain.find({ query: 'recent documents about machine learning' })
|
||||||
await brain.find({ query: 'articles created this week' })
|
await brain.find({ query: 'articles created this week' })
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue