chore: remove example files and release configuration

Deleted augmentation pipeline examples and `.releaserc.json`, streamlining the repository by eliminating redundant example implementations and release automation files.
This commit is contained in:
David Snelling 2025-05-27 13:58:49 -07:00
parent a22fd7de77
commit 5566ddfb09
14 changed files with 169 additions and 1474 deletions

View file

@ -1,37 +0,0 @@
name: Release
on:
push:
branches:
- main
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Test
run: npm test
- name: Semantic Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release

View file

@ -1,16 +0,0 @@
{
"branches": ["main"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/npm",
"@semantic-release/github",
[
"@semantic-release/git",
{
"assets": ["package.json"],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
]
]
}

View file

@ -1,64 +1,30 @@
# Contributing to Soulcraft Brainy
Thank you for your interest in contributing to Soulcraft Brainy! This document provides guidelines and instructions for contributing to the project.
Thank you for your interest in contributing to Soulcraft Brainy! This document provides guidelines and instructions for
contributing to the project.
## Commit Message Guidelines
This project uses [Conventional Commits](https://www.conventionalcommits.org/) for automatic semantic versioning. Your commit messages determine how the version number is incremented.
When contributing to this project, please write clear and descriptive commit messages that explain the purpose of your changes. Good commit messages help maintainers understand your contributions and make the review process smoother.
### Commit Message Format
### Best Practices
Each commit message consists of a **header**, a **body**, and a **footer**:
```
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
```
The **header** is mandatory and must conform to the following format:
- **type**: What kind of change is this commit making? (required)
- **scope**: What part of the codebase does this change affect? (optional)
- **description**: A short description of the change (required)
### Types
- **feat**: A new feature (triggers a minor version bump)
- **fix**: A bug fix (triggers a patch version bump)
- **docs**: Documentation only changes
- **style**: Changes that do not affect the meaning of the code (white-space, formatting, etc.)
- **refactor**: A code change that neither fixes a bug nor adds a feature
- **perf**: A code change that improves performance
- **test**: Adding missing tests or correcting existing tests
- **chore**: Changes to the build process or auxiliary tools and libraries
### Breaking Changes
Breaking changes should be indicated by:
1. Adding an exclamation mark after the type/scope: `feat!: remove deprecated API`
2. Adding a `BREAKING CHANGE:` footer:
```
feat: change API parameter order
BREAKING CHANGE: The order of parameters in the API has changed.
```
Both methods will trigger a major version bump.
- Keep the first line concise (ideally under 50 characters)
- Use the imperative mood ("Add feature" not "Added feature")
- Reference issues and pull requests where appropriate
- When necessary, provide more detailed explanations in the commit body
### Examples
```
feat: add vector normalization option
fix: correct distance calculation in HNSW search
docs: update API documentation
feat(storage): add support for IndexedDB
fix!: change API parameter order
refactor: simplify vector comparison logic
test: add tests for metadata filtering
chore: update build dependencies
Add vector normalization option
Fix distance calculation in HNSW search
Update API documentation
Add support for IndexedDB storage
Change API parameter order
Simplify vector comparison logic
Add tests for metadata filtering
Update build dependencies
```
## Pull Request Process

114
README.md
View file

@ -55,6 +55,11 @@ const catResults = await db.search("cat", 2);
console.log(catResults);
// Results will include vectors similar to the embedding of "cat"
// Use the dedicated text search method for simpler code
const lionResults = await db.searchText("lion", 2);
console.log(lionResults);
// Results will include vectors similar to the embedding of "lion"
// Get a vector by ID
const cat = await db.get(catId);
console.log(cat);
@ -70,6 +75,46 @@ await db.delete(fishId);
await db.clear();
```
### Using the Embedding Function
You can directly use the same embedding function that the database uses internally:
```typescript
import {BrainyData} from '@soulcraft/brainy';
// Create a new vector database
const db = new BrainyData();
await db.init();
// Embed a single text string
const catVector = await db.embed("cat");
console.log(catVector);
// [0.123, 0.456, 0.789, ...] - Vector representation of "cat"
// Embed multiple texts at once
const animalVectors = await db.embed(["cat", "dog", "fish"]);
console.log(animalVectors);
// [0.123, 0.456, 0.789, ...] - Vector representation of the first item in the array
// You can also use the exported embedding classes directly
import {UniversalSentenceEncoder, createEmbeddingFunction} from '@soulcraft/brainy';
// Create a new Universal Sentence Encoder model
const useModel = new UniversalSentenceEncoder();
await useModel.init();
// Create an embedding function from the model
const embedFunction = createEmbeddingFunction(useModel);
// Embed text using the function
const vector = await embedFunction("Some text to embed");
console.log(vector);
// [0.123, 0.456, 0.789, ...] - Vector representation of "Some text to embed"
// Don't forget to dispose of the model when done
await useModel.dispose();
```
### Configuration Options
```typescript
@ -121,60 +166,49 @@ Soulcraft Brainy is configured as a private NPM package with restricted access.
### Versioning
This project uses semantic versioning (SemVer) with automatic version determination based on conventional commit messages. The version is automatically bumped when code is merged to the main branch, according to the following rules:
This project uses semantic versioning (SemVer):
- **Major version** (`x.0.0`): Breaking changes, indicated by commits with `BREAKING CHANGE:` in the body or commits of type `feat` with `!` (e.g., `feat!: remove deprecated API`)
- **Minor version** (`0.x.0`): New features that don't break existing functionality, indicated by commits of type `feat`
- **Patch version** (`0.0.x`): Bug fixes and other minor changes, indicated by commits of type `fix`
- **Major version** (`x.0.0`): Breaking changes that may require updates to dependent code
- **Minor version** (`0.x.0`): New features that don't break existing functionality
- **Patch version** (`0.0.x`): Bug fixes and other minor changes
#### Commit Message Format
The package includes scripts for manual version bumping:
To ensure proper versioning, commit messages should follow the [Conventional Commits](https://www.conventionalcommits.org/) specification:
```bash
# Increment patch version (0.0.x)
npm run version:patch
```
<type>[optional scope]: <description>
# Increment minor version (0.x.0)
npm run version:minor
[optional body]
[optional footer(s)]
# Increment major version (x.0.0)
npm run version:major
```
Common types include:
- `feat`: A new feature (minor version bump)
- `fix`: A bug fix (patch version bump)
- `docs`: Documentation changes
- `style`: Changes that don't affect code functionality (formatting, etc.)
- `refactor`: Code changes that neither fix bugs nor add features
- `perf`: Performance improvements
- `test`: Adding or correcting tests
- `chore`: Changes to the build process or auxiliary tools
Examples:
```
feat: add new vector normalization option
fix: correct distance calculation in HNSW search
docs: update API documentation
feat(storage): add support for IndexedDB
fix!: change API parameter order (this will cause a major version bump)
```
These commands will update the version in package.json and create a git tag for the new version.
### Publishing the Package
The package is automatically published when changes are merged to the main branch. The GitHub Actions workflow will:
1. Determine the appropriate version bump based on commit messages
2. Update the version in package.json
3. Create a new GitHub release with release notes
4. Publish the package to npm
For manual publishing (if needed):
To publish updates to the package:
1. Ensure you have the appropriate npm credentials and access to the @soulcraft organization
2. Build the package:
2. Update the version using one of the version scripts:
```bash
npm run version:patch # For bug fixes and minor changes
npm run version:minor # For new features
npm run version:major # For breaking changes
```
3. Use the deploy script to build and publish the package:
```bash
npm run deploy
```
Alternatively, you can run the steps separately:
1. Build the package:
```bash
npm run build
```
3. Publish the package:
2. Publish the package:
```bash
npm publish
```
@ -667,11 +701,13 @@ constructor(config?: BrainyDataConfig)
- `add(vectorOrData: Vector | any, metadata?: T, options?: { forceEmbed?: boolean }): Promise<string>` - Add a vector or data to the database
- `addBatch(items: Array<{ vectorOrData: Vector | any, metadata?: T }>, options?: { forceEmbed?: boolean }): Promise<string[]>` - Add multiple vectors or data items
- `search(queryVectorOrData: Vector | any, k?: number, options?: { forceEmbed?: boolean }): Promise<SearchResult<T>[]>` - Search for similar vectors
- `searchText(query: string, k?: number): Promise<SearchResult<T>[]>` - Search for similar documents using a text query
- `get(id: string): Promise<VectorDocument<T> | null>` - Get a vector by ID
- `delete(id: string): Promise<boolean>` - Delete a vector
- `updateMetadata(id: string, metadata: T): Promise<boolean>` - Update metadata
- `clear(): Promise<void>` - Clear the database
- `size(): number` - Get the number of vectors in the database
- `embed(data: string | string[]): Promise<Vector>` - Embed text or data into a vector using the same embedding function used by this instance
### Distance Functions

8
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "brainy",
"version": "0.1.0",
"name": "@soulcraft/brainy",
"version": "0.1.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "brainy",
"version": "0.1.0",
"name": "@soulcraft/brainy",
"version": "0.1.1",
"license": "MIT",
"dependencies": {
"@tensorflow-models/universal-sentence-encoder": "^1.3.3",

View file

@ -1,6 +1,6 @@
{
"name": "@soulcraft/brainy",
"version": "0.1.0",
"version": "0.1.1",
"description": "A vector database using HNSW indexing with Origin Private File System storage",
"main": "dist/index.js",
"module": "dist/index.js",
@ -19,7 +19,11 @@
"scripts": {
"build": "tsc",
"test": "jest",
"start": "node dist/index.js"
"start": "node dist/index.js",
"version:patch": "npm version patch",
"version:minor": "npm version minor",
"version:major": "npm version major",
"deploy": "npm run build && npm publish"
},
"keywords": [
"vector-database",
@ -35,11 +39,6 @@
"access": "restricted"
},
"devDependencies": {
"@semantic-release/commit-analyzer": "^9.0.2",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^8.0.7",
"@semantic-release/npm": "^9.0.2",
"@semantic-release/release-notes-generator": "^10.0.3",
"@types/jest": "^29.5.3",
"@types/node": "^20.4.5",
"@types/uuid": "^10.0.0",
@ -47,7 +46,6 @@
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.45.0",
"jest": "^29.6.2",
"semantic-release": "^20.1.3",
"ts-jest": "^29.1.1",
"typescript": "^5.1.6"
},

View file

@ -235,7 +235,7 @@ export class AugmentationPipeline {
method: M & (BrainyAugmentations.ISenseAugmentation[M] extends (...args: any[]) => any ? M : never),
args: Parameters<Extract<BrainyAugmentations.ISenseAugmentation[M], (...args: any[]) => any>>,
options: PipelineOptions = {}
): Promise<AugmentationResponse<R>[]> {
): Promise<Promise<{ success: boolean; data: R; error?: string }>[]> {
const opts = { ...DEFAULT_PIPELINE_OPTIONS, ...options }
return this.executeTypedPipeline<BrainyAugmentations.ISenseAugmentation, M, R>(
this.registry.sense,
@ -260,7 +260,7 @@ export class AugmentationPipeline {
method: M & (BrainyAugmentations.IConduitAugmentation[M] extends (...args: any[]) => any ? M : never),
args: Parameters<Extract<BrainyAugmentations.IConduitAugmentation[M], (...args: any[]) => any>>,
options: PipelineOptions = {}
): Promise<AugmentationResponse<R>[]> {
): Promise<Promise<{ success: boolean; data: R; error?: string }>[]> {
const opts = { ...DEFAULT_PIPELINE_OPTIONS, ...options }
return this.executeTypedPipeline<BrainyAugmentations.IConduitAugmentation, M, R>(
this.registry.conduit,
@ -285,7 +285,7 @@ export class AugmentationPipeline {
method: M & (BrainyAugmentations.ICognitionAugmentation[M] extends (...args: any[]) => any ? M : never),
args: Parameters<Extract<BrainyAugmentations.ICognitionAugmentation[M], (...args: any[]) => any>>,
options: PipelineOptions = {}
): Promise<AugmentationResponse<R>[]> {
): Promise<Promise<{ success: boolean; data: R; error?: string }>[]> {
const opts = { ...DEFAULT_PIPELINE_OPTIONS, ...options }
return this.executeTypedPipeline<BrainyAugmentations.ICognitionAugmentation, M, R>(
this.registry.cognition,
@ -310,7 +310,7 @@ export class AugmentationPipeline {
method: M & (BrainyAugmentations.IMemoryAugmentation[M] extends (...args: any[]) => any ? M : never),
args: Parameters<Extract<BrainyAugmentations.IMemoryAugmentation[M], (...args: any[]) => any>>,
options: PipelineOptions = {}
): Promise<AugmentationResponse<R>[]> {
): Promise<Promise<{ success: boolean; data: R; error?: string }>[]> {
const opts = { ...DEFAULT_PIPELINE_OPTIONS, ...options }
return this.executeTypedPipeline<BrainyAugmentations.IMemoryAugmentation, M, R>(
this.registry.memory,
@ -335,7 +335,7 @@ export class AugmentationPipeline {
method: M & (BrainyAugmentations.IPerceptionAugmentation[M] extends (...args: any[]) => any ? M : never),
args: Parameters<Extract<BrainyAugmentations.IPerceptionAugmentation[M], (...args: any[]) => any>>,
options: PipelineOptions = {}
): Promise<AugmentationResponse<R>[]> {
): Promise<Promise<{ success: boolean; data: R; error?: string }>[]> {
const opts = { ...DEFAULT_PIPELINE_OPTIONS, ...options }
return this.executeTypedPipeline<BrainyAugmentations.IPerceptionAugmentation, M, R>(
this.registry.perception,
@ -360,7 +360,7 @@ export class AugmentationPipeline {
method: M & (BrainyAugmentations.IDialogAugmentation[M] extends (...args: any[]) => any ? M : never),
args: Parameters<Extract<BrainyAugmentations.IDialogAugmentation[M], (...args: any[]) => any>>,
options: PipelineOptions = {}
): Promise<AugmentationResponse<R>[]> {
): Promise<Promise<{ success: boolean; data: R; error?: string }>[]> {
const opts = { ...DEFAULT_PIPELINE_OPTIONS, ...options }
return this.executeTypedPipeline<BrainyAugmentations.IDialogAugmentation, M, R>(
this.registry.dialog,
@ -385,7 +385,7 @@ export class AugmentationPipeline {
method: M & (BrainyAugmentations.IActivationAugmentation[M] extends (...args: any[]) => any ? M : never),
args: Parameters<Extract<BrainyAugmentations.IActivationAugmentation[M], (...args: any[]) => any>>,
options: PipelineOptions = {}
): Promise<AugmentationResponse<R>[]> {
): Promise<Promise<{ success: boolean; data: R; error?: string }>[]> {
const opts = { ...DEFAULT_PIPELINE_OPTIONS, ...options }
return this.executeTypedPipeline<BrainyAugmentations.IActivationAugmentation, M, R>(
this.registry.activation,
@ -538,10 +538,10 @@ export class AugmentationPipeline {
// Create a timeout promise if a timeout is specified
const timeoutPromise = options.timeout
? new Promise<{
success: boolean
data: R
error?: string
}>((_, reject) => {
success: boolean
data: R
error?: string
}>((_, reject) => {
setTimeout(() => {
reject(new Error(`Timeout executing ${String(method)} on ${augmentation.name}`))
}, options.timeout)

View file

@ -535,6 +535,47 @@ export class BrainyData<T = any> {
return this.index.size()
}
/**
* Embed text or data into a vector using the same embedding function used by this instance
* This allows clients to use the same TensorFlow Universal Sentence Encoder throughout their application
*
* @param data Text or data to embed
* @returns A promise that resolves to the embedded vector
*/
public async embed(data: string | string[]): Promise<Vector> {
await this.ensureInitialized()
try {
return await this.embeddingFunction(data)
} catch (error) {
console.error('Failed to embed data:', error)
throw new Error(`Failed to embed data: ${error}`)
}
}
/**
* Search for similar documents using a text query
* This is a convenience method that embeds the query text and performs a search
*
* @param query Text query to search for
* @param k Number of results to return
* @returns Array of search results
*/
public async searchText(query: string, k: number = 10): Promise<SearchResult<T>[]> {
await this.ensureInitialized()
try {
// Embed the query text
const queryVector = await this.embed(query)
// Search using the embedded vector
return await this.search(queryVector, k)
} catch (error) {
console.error('Failed to search with text query:', error)
throw new Error(`Failed to search with text query: ${error}`)
}
}
/**
* Ensure the database is initialized
*/

View file

@ -1,266 +0,0 @@
/**
* Augmentation Pipeline Example
*
* This example demonstrates how to use the augmentation pipeline to register
* and execute multiple augmentations of each type.
*/
import {
augmentationPipeline,
ExecutionMode,
PipelineOptions,
IAugmentation,
AugmentationResponse,
BrainyAugmentations
} from '../index.js'
/**
* Example Cognition Augmentation
*/
class SimpleCognitionAugmentation implements BrainyAugmentations.ICognitionAugmentation {
readonly name = 'simple-cognition'
readonly description = 'A simple cognition augmentation for demonstration'
async initialize(): Promise<void> {
console.log('Initializing SimpleCognitionAugmentation')
}
async shutDown(): Promise<void> {
console.log('Shutting down SimpleCognitionAugmentation')
}
async getStatus(): Promise<'active' | 'inactive' | 'error'> {
return 'active'
}
async reason(
query: string,
context?: Record<string, unknown>
): Promise<AugmentationResponse<{ inference: string; confidence: number }>> {
console.log(`SimpleCognitionAugmentation reasoning about: ${query}`)
console.log('Context:', context)
return {
success: true,
data: {
inference: `Simple inference about: ${query}`,
confidence: 0.7
}
}
}
async infer(
dataSubset: Record<string, unknown>
): Promise<AugmentationResponse<Record<string, unknown>>> {
return {
success: true,
data: {
result: `Inferred from data: ${JSON.stringify(dataSubset)}`
}
}
}
async executeLogic(
ruleId: string,
input: Record<string, unknown>
): Promise<AugmentationResponse<boolean>> {
return {
success: true,
data: true
}
}
}
/**
* Another Example Cognition Augmentation
*/
class AdvancedCognitionAugmentation implements BrainyAugmentations.ICognitionAugmentation {
readonly name = 'advanced-cognition'
readonly description = 'A more advanced cognition augmentation for demonstration'
async initialize(): Promise<void> {
console.log('Initializing AdvancedCognitionAugmentation')
}
async shutDown(): Promise<void> {
console.log('Shutting down AdvancedCognitionAugmentation')
}
async getStatus(): Promise<'active' | 'inactive' | 'error'> {
return 'active'
}
async reason(
query: string,
context?: Record<string, unknown>
): Promise<AugmentationResponse<{ inference: string; confidence: number }>> {
console.log(`AdvancedCognitionAugmentation reasoning about: ${query}`)
console.log('Context:', context)
return {
success: true,
data: {
inference: `Advanced inference about: ${query} with detailed analysis`,
confidence: 0.9
}
}
}
async infer(
dataSubset: Record<string, unknown>
): Promise<AugmentationResponse<Record<string, unknown>>> {
return {
success: true,
data: {
result: `Advanced inference from data: ${JSON.stringify(dataSubset)}`,
additionalInsights: ['insight1', 'insight2']
}
}
}
async executeLogic(
ruleId: string,
input: Record<string, unknown>
): Promise<AugmentationResponse<boolean>> {
return {
success: true,
data: true
}
}
}
/**
* Example Sense Augmentation
*/
class SimpleSenseAugmentation implements BrainyAugmentations.ISenseAugmentation {
readonly name = 'simple-sense'
readonly description = 'A simple sense augmentation for demonstration'
async initialize(): Promise<void> {
console.log('Initializing SimpleSenseAugmentation')
}
async shutDown(): Promise<void> {
console.log('Shutting down SimpleSenseAugmentation')
}
async getStatus(): Promise<'active' | 'inactive' | 'error'> {
return 'active'
}
async processRawData(
rawData: Buffer | string,
dataType: string
): Promise<AugmentationResponse<{ nouns: string[]; verbs: string[] }>> {
console.log(`SimpleSenseAugmentation processing ${dataType} data:`,
typeof rawData === 'string' ? rawData : 'Buffer data')
return {
success: true,
data: {
nouns: ['example', 'data', 'processing'],
verbs: ['process', 'analyze', 'extract']
}
}
}
async listenToFeed(
feedUrl: string,
callback: (data: { nouns: string[]; verbs: string[] }) => void
): Promise<void> {
console.log(`SimpleSenseAugmentation listening to feed: ${feedUrl}`)
// In a real implementation, this would set up a listener
}
}
/**
* Main function to demonstrate the augmentation pipeline
*/
async function main() {
try {
console.log('=== Augmentation Pipeline Example ===')
// Create augmentation instances
const simpleCognition = new SimpleCognitionAugmentation()
const advancedCognition = new AdvancedCognitionAugmentation()
const simpleSense = new SimpleSenseAugmentation()
// Register augmentations with the pipeline
augmentationPipeline
.register(simpleCognition)
.register(advancedCognition)
.register(simpleSense)
// Initialize all registered augmentations
console.log('\n=== Initializing Augmentations ===')
await augmentationPipeline.initialize()
// Execute a cognition pipeline in sequential mode (default)
console.log('\n=== Executing Cognition Pipeline (Sequential) ===')
const reasoningResults = await augmentationPipeline.executeCognitionPipeline(
'reason',
['What is the capital of France?', { additionalContext: 'geography' }]
)
console.log('\nReasoning Results:')
reasoningResults.forEach((result, index) => {
console.log(`Result ${index + 1}:`)
console.log(` Success: ${result.success}`)
if (result.success) {
console.log(` Inference: ${result.data.inference}`)
console.log(` Confidence: ${result.data.confidence}`)
} else {
console.log(` Error: ${result.error}`)
}
})
// Execute a cognition pipeline in parallel mode
console.log('\n=== Executing Cognition Pipeline (Parallel) ===')
const inferResults = await augmentationPipeline.executeCognitionPipeline(
'infer',
[{ topic: 'climate change', data: [1, 2, 3] }],
{ mode: ExecutionMode.PARALLEL }
)
console.log('\nInference Results:')
inferResults.forEach((result, index) => {
console.log(`Result ${index + 1}:`)
console.log(` Success: ${result.success}`)
if (result.success) {
console.log(` Data: ${JSON.stringify(result.data)}`)
} else {
console.log(` Error: ${result.error}`)
}
})
// Execute a sense pipeline
console.log('\n=== Executing Sense Pipeline ===')
const processingResults = await augmentationPipeline.executeSensePipeline(
'processRawData',
['This is some example text to process', 'text']
)
console.log('\nProcessing Results:')
processingResults.forEach((result, index) => {
console.log(`Result ${index + 1}:`)
console.log(` Success: ${result.success}`)
if (result.success) {
console.log(` Nouns: ${result.data.nouns.join(', ')}`)
console.log(` Verbs: ${result.data.verbs.join(', ')}`)
} else {
console.log(` Error: ${result.error}`)
}
})
// Shut down all registered augmentations
console.log('\n=== Shutting Down Augmentations ===')
await augmentationPipeline.shutDown()
console.log('\n=== Example Complete ===')
} catch (error) {
console.error('Error in augmentation pipeline example:', error)
}
}
// Run the example
main()

View file

@ -1,76 +0,0 @@
/**
* Example demonstrating how to use the FileSystemStorage adapter with a custom directory
*/
import { BrainyData } from '../brainyData.js'
import { FileSystemStorage } from '../storage/fileSystemStorage.js'
import path from 'path'
// Example data - word embeddings
const wordEmbeddings = {
'cat': [0.2, 0.3, 0.4, 0.1],
'dog': [0.3, 0.2, 0.4, 0.2],
'fish': [0.1, 0.1, 0.8, 0.2]
}
// Example metadata
const metadata: {
[key: string]: { type: string; [key]: boolean } | undefined | null
} = {
'cat': { type: 'mammal', domesticated: true },
'dog': { type: 'mammal', domesticated: true },
'fish': { type: 'fish', domesticated: false }
}
/**
* Run the example
*/
async function runExample() {
console.log('Initializing vector database with custom storage location...')
// Create a custom storage adapter with a specific directory
// This will store data in ./custom-data directory relative to the current working directory
const customStoragePath = path.join(process.cwd(), 'custom-data')
const storageAdapter = new FileSystemStorage(customStoragePath)
// Create a new vector database with the custom storage adapter
const db = new BrainyData({
storageAdapter
})
await db.init()
console.log(`Using custom storage location: ${customStoragePath}`)
console.log('Adding vectors to the database...')
// Add vectors to the database
const ids: Record<string, string> = {}
for (const [word, vector] of Object.entries(wordEmbeddings)) {
ids[word] = await db.add(vector, metadata[word])
console.log(`Added "${word}" with ID: ${ids[word]}`)
}
console.log('\nDatabase size:', db.size())
// Search for similar vectors
console.log('\nSearching for vectors similar to "cat"...')
const catResults = await db.search(wordEmbeddings['cat'], 2)
console.log('Results:')
for (const result of catResults) {
const word = Object.entries(ids).find(([_, id]) => id === result.id)?.[0] || 'unknown'
console.log(`- ${word} (score: ${result.score.toFixed(4)}, metadata:`, result.metadata, ')')
}
console.log('\nExample completed successfully!')
console.log(`Data has been stored in: ${customStoragePath}`)
console.log('You can restart this example to verify that data persists between runs.')
}
// Only run in Node.js environment
if (typeof process !== 'undefined' && process.versions && process.versions.node) {
runExample().catch(error => {
console.error('Error running example:', error)
})
} else {
console.error('This example is designed to run in Node.js environments only.')
}

View file

@ -1,755 +0,0 @@
/**
* Memory Augmentation Example
*
* This example demonstrates how to create and register memory augmentations
* for storing data in different formats (e.g., fileSystem, in memory, or firestore).
*/
import {
augmentationPipeline,
IAugmentation,
IWebSocketSupport,
IWebSocketMemoryAugmentation,
AugmentationResponse,
BrainyAugmentations,
ExecutionMode
} from '../index.js'
/**
* Example In-Memory Augmentation
*
* This augmentation stores data in memory using a JavaScript Map.
*/
class InMemoryAugmentation implements BrainyAugmentations.IMemoryAugmentation {
readonly name = 'in-memory-storage'
readonly description = 'A simple in-memory storage augmentation'
private storage: Map<string, unknown> = new Map()
async initialize(): Promise<void> {
console.log('Initializing InMemoryAugmentation')
}
async shutDown(): Promise<void> {
console.log('Shutting down InMemoryAugmentation')
this.storage.clear()
}
async getStatus(): Promise<'active' | 'inactive' | 'error'> {
return 'active'
}
async storeData(
key: string,
data: unknown,
options?: Record<string, unknown>
): Promise<AugmentationResponse<boolean>> {
console.log(`Storing data with key: ${key}`)
try {
this.storage.set(key, data)
return {
success: true,
data: true
}
} catch (error) {
return {
success: false,
data: false,
error: error instanceof Error ? error.message : String(error)
}
}
}
async retrieveData(
key: string,
options?: Record<string, unknown>
): Promise<AugmentationResponse<unknown>> {
console.log(`Retrieving data with key: ${key}`)
try {
if (!this.storage.has(key)) {
return {
success: false,
data: null,
error: `Key not found: ${key}`
}
}
return {
success: true,
data: this.storage.get(key)
}
} catch (error) {
return {
success: false,
data: null,
error: error instanceof Error ? error.message : String(error)
}
}
}
async updateData(
key: string,
data: unknown,
options?: Record<string, unknown>
): Promise<AugmentationResponse<boolean>> {
console.log(`Updating data with key: ${key}`)
try {
if (!this.storage.has(key)) {
return {
success: false,
data: false,
error: `Key not found: ${key}`
}
}
this.storage.set(key, data)
return {
success: true,
data: true
}
} catch (error) {
return {
success: false,
data: false,
error: error instanceof Error ? error.message : String(error)
}
}
}
async deleteData(
key: string,
options?: Record<string, unknown>
): Promise<AugmentationResponse<boolean>> {
console.log(`Deleting data with key: ${key}`)
try {
if (!this.storage.has(key)) {
return {
success: false,
data: false,
error: `Key not found: ${key}`
}
}
this.storage.delete(key)
return {
success: true,
data: true
}
} catch (error) {
return {
success: false,
data: false,
error: error instanceof Error ? error.message : String(error)
}
}
}
async listDataKeys(
pattern?: string,
options?: Record<string, unknown>
): Promise<AugmentationResponse<string[]>> {
console.log(`Listing data keys with pattern: ${pattern || 'all'}`)
try {
const keys = Array.from(this.storage.keys())
// Filter keys by pattern if provided
const filteredKeys = pattern
? keys.filter(key => key.includes(pattern))
: keys
return {
success: true,
data: filteredKeys
}
} catch (error) {
return {
success: false,
data: [],
error: error instanceof Error ? error.message : String(error)
}
}
}
}
/**
* Example File System Memory Augmentation
*
* This augmentation simulates storing data in the file system.
*/
class FileSystemMemoryAugmentation implements BrainyAugmentations.IMemoryAugmentation {
readonly name = 'file-system-storage'
readonly description = 'A file system storage augmentation'
private storage: Map<string, unknown> = new Map()
async initialize(): Promise<void> {
console.log('Initializing FileSystemMemoryAugmentation')
console.log('Simulating file system initialization...')
}
async shutDown(): Promise<void> {
console.log('Shutting down FileSystemMemoryAugmentation')
console.log('Simulating file system cleanup...')
this.storage.clear()
}
async getStatus(): Promise<'active' | 'inactive' | 'error'> {
return 'active'
}
async storeData(
key: string,
data: unknown,
options?: Record<string, unknown>
): Promise<AugmentationResponse<boolean>> {
console.log(`Storing data in file system with key: ${key}`)
try {
// Simulate file system operations
console.log(`Writing to file: ${key}.json`)
this.storage.set(key, data)
return {
success: true,
data: true
}
} catch (error) {
return {
success: false,
data: false,
error: error instanceof Error ? error.message : String(error)
}
}
}
async retrieveData(
key: string,
options?: Record<string, unknown>
): Promise<AugmentationResponse<unknown>> {
console.log(`Retrieving data from file system with key: ${key}`)
try {
if (!this.storage.has(key)) {
return {
success: false,
data: null,
error: `File not found: ${key}.json`
}
}
// Simulate file system operations
console.log(`Reading from file: ${key}.json`)
return {
success: true,
data: this.storage.get(key)
}
} catch (error) {
return {
success: false,
data: null,
error: error instanceof Error ? error.message : String(error)
}
}
}
async updateData(
key: string,
data: unknown,
options?: Record<string, unknown>
): Promise<AugmentationResponse<boolean>> {
console.log(`Updating data in file system with key: ${key}`)
try {
if (!this.storage.has(key)) {
return {
success: false,
data: false,
error: `File not found: ${key}.json`
}
}
// Simulate file system operations
console.log(`Updating file: ${key}.json`)
this.storage.set(key, data)
return {
success: true,
data: true
}
} catch (error) {
return {
success: false,
data: false,
error: error instanceof Error ? error.message : String(error)
}
}
}
async deleteData(
key: string,
options?: Record<string, unknown>
): Promise<AugmentationResponse<boolean>> {
console.log(`Deleting data from file system with key: ${key}`)
try {
if (!this.storage.has(key)) {
return {
success: false,
data: false,
error: `File not found: ${key}.json`
}
}
// Simulate file system operations
console.log(`Deleting file: ${key}.json`)
this.storage.delete(key)
return {
success: true,
data: true
}
} catch (error) {
return {
success: false,
data: false,
error: error instanceof Error ? error.message : String(error)
}
}
}
async listDataKeys(
pattern?: string,
options?: Record<string, unknown>
): Promise<AugmentationResponse<string[]>> {
console.log(`Listing data keys from file system with pattern: ${pattern || 'all'}`)
try {
// Simulate file system operations
console.log('Reading directory contents...')
const keys = Array.from(this.storage.keys())
// Filter keys by pattern if provided
const filteredKeys = pattern
? keys.filter(key => key.includes(pattern))
: keys
return {
success: true,
data: filteredKeys
}
} catch (error) {
return {
success: false,
data: [],
error: error instanceof Error ? error.message : String(error)
}
}
}
}
/**
* Example Combined WebSocket and Memory Augmentation
*
* This augmentation implements both WebSocket and Memory interfaces.
*/
class WebSocketMemoryAugmentation implements IWebSocketMemoryAugmentation {
readonly name = 'websocket-memory-storage'
readonly description = 'A combined WebSocket and Memory storage augmentation'
private storage: Map<string, unknown> = new Map()
private connections: Map<string, { url: string, status: 'connected' | 'disconnected' | 'error' }> = new Map()
async initialize(): Promise<void> {
console.log('Initializing WebSocketMemoryAugmentation')
}
async shutDown(): Promise<void> {
console.log('Shutting down WebSocketMemoryAugmentation')
this.storage.clear()
this.connections.clear()
}
async getStatus(): Promise<'active' | 'inactive' | 'error'> {
return 'active'
}
// WebSocket methods
async connectWebSocket(url: string, protocols?: string | string[]): Promise<{
connectionId: string;
url: string;
status: 'connected' | 'disconnected' | 'error'
}> {
console.log(`WebSocketMemory connecting to WebSocket at ${url}`)
const connectionId = `ws-memory-${Date.now()}`
this.connections.set(connectionId, { url, status: 'connected' })
return {
connectionId,
url,
status: 'connected'
}
}
async sendWebSocketMessage(connectionId: string, data: unknown): Promise<void> {
console.log(`WebSocketMemory sending message to WebSocket ${connectionId}:`, data)
if (!this.connections.has(connectionId)) {
throw new Error(`Connection not found: ${connectionId}`)
}
}
async onWebSocketMessage(connectionId: string, callback: (data: unknown) => void): Promise<void> {
console.log(`WebSocketMemory registering callback for WebSocket ${connectionId}`)
if (!this.connections.has(connectionId)) {
throw new Error(`Connection not found: ${connectionId}`)
}
}
async closeWebSocket(connectionId: string, code?: number, reason?: string): Promise<void> {
console.log(`WebSocketMemory closing WebSocket ${connectionId}`)
if (!this.connections.has(connectionId)) {
throw new Error(`Connection not found: ${connectionId}`)
}
this.connections.delete(connectionId)
}
// Memory methods
async storeData(
key: string,
data: unknown,
options?: Record<string, unknown>
): Promise<AugmentationResponse<boolean>> {
console.log(`WebSocketMemory storing data with key: ${key}`)
try {
this.storage.set(key, data)
// If a WebSocket connection is specified in options, send the data through it
const connectionId = options?.connectionId as string
if (connectionId && this.connections.has(connectionId)) {
await this.sendWebSocketMessage(connectionId, {
action: 'store',
key,
data
})
}
return {
success: true,
data: true
}
} catch (error) {
return {
success: false,
data: false,
error: error instanceof Error ? error.message : String(error)
}
}
}
async retrieveData(
key: string,
options?: Record<string, unknown>
): Promise<AugmentationResponse<unknown>> {
console.log(`WebSocketMemory retrieving data with key: ${key}`)
try {
if (!this.storage.has(key)) {
return {
success: false,
data: null,
error: `Key not found: ${key}`
}
}
const data = this.storage.get(key)
// If a WebSocket connection is specified in options, send the request through it
const connectionId = options?.connectionId as string
if (connectionId && this.connections.has(connectionId)) {
await this.sendWebSocketMessage(connectionId, {
action: 'retrieve',
key
})
}
return {
success: true,
data
}
} catch (error) {
return {
success: false,
data: null,
error: error instanceof Error ? error.message : String(error)
}
}
}
async updateData(
key: string,
data: unknown,
options?: Record<string, unknown>
): Promise<AugmentationResponse<boolean>> {
console.log(`WebSocketMemory updating data with key: ${key}`)
try {
if (!this.storage.has(key)) {
return {
success: false,
data: false,
error: `Key not found: ${key}`
}
}
this.storage.set(key, data)
// If a WebSocket connection is specified in options, send the update through it
const connectionId = options?.connectionId as string
if (connectionId && this.connections.has(connectionId)) {
await this.sendWebSocketMessage(connectionId, {
action: 'update',
key,
data
})
}
return {
success: true,
data: true
}
} catch (error) {
return {
success: false,
data: false,
error: error instanceof Error ? error.message : String(error)
}
}
}
async deleteData(
key: string,
options?: Record<string, unknown>
): Promise<AugmentationResponse<boolean>> {
console.log(`WebSocketMemory deleting data with key: ${key}`)
try {
if (!this.storage.has(key)) {
return {
success: false,
data: false,
error: `Key not found: ${key}`
}
}
this.storage.delete(key)
// If a WebSocket connection is specified in options, send the delete request through it
const connectionId = options?.connectionId as string
if (connectionId && this.connections.has(connectionId)) {
await this.sendWebSocketMessage(connectionId, {
action: 'delete',
key
})
}
return {
success: true,
data: true
}
} catch (error) {
return {
success: false,
data: false,
error: error instanceof Error ? error.message : String(error)
}
}
}
async listDataKeys(
pattern?: string,
options?: Record<string, unknown>
): Promise<AugmentationResponse<string[]>> {
console.log(`WebSocketMemory listing data keys with pattern: ${pattern || 'all'}`)
try {
const keys = Array.from(this.storage.keys())
// Filter keys by pattern if provided
const filteredKeys = pattern
? keys.filter(key => key.includes(pattern))
: keys
// If a WebSocket connection is specified in options, send the list request through it
const connectionId = options?.connectionId as string
if (connectionId && this.connections.has(connectionId)) {
await this.sendWebSocketMessage(connectionId, {
action: 'list',
pattern
})
}
return {
success: true,
data: filteredKeys
}
} catch (error) {
return {
success: false,
data: [],
error: error instanceof Error ? error.message : String(error)
}
}
}
}
/**
* Main function to demonstrate the memory augmentation
*/
async function main() {
try {
console.log('=== Memory Augmentation Example ===')
// Create augmentation instances
const inMemoryStorage = new InMemoryAugmentation()
const fileSystemStorage = new FileSystemMemoryAugmentation()
const webSocketMemory = new WebSocketMemoryAugmentation()
// Register augmentations with the pipeline
augmentationPipeline
.register(inMemoryStorage)
.register(fileSystemStorage)
.register(webSocketMemory)
// Initialize all registered augmentations
console.log('\n=== Initializing Augmentations ===')
await augmentationPipeline.initialize()
// Store data in all memory augmentations
console.log('\n=== Storing Data ===')
const storeResults = await augmentationPipeline.executeMemoryPipeline(
'storeData',
['user123', { name: 'John Doe', email: 'john@example.com' }]
)
console.log('\nStore Results:')
storeResults.forEach((result, index) => {
console.log(`Result ${index + 1}:`)
console.log(` Success: ${result.success}`)
if (!result.success) {
console.log(` Error: ${result.error}`)
}
})
// Retrieve data from all memory augmentations
console.log('\n=== Retrieving Data ===')
const retrieveResults = await augmentationPipeline.executeMemoryPipeline(
'retrieveData',
['user123']
)
console.log('\nRetrieve Results:')
retrieveResults.forEach((result, index) => {
console.log(`Result ${index + 1}:`)
console.log(` Success: ${result.success}`)
if (result.success) {
console.log(` Data: ${JSON.stringify(result.data)}`)
} else {
console.log(` Error: ${result.error}`)
}
})
// Update data in all memory augmentations
console.log('\n=== Updating Data ===')
const updateResults = await augmentationPipeline.executeMemoryPipeline(
'updateData',
['user123', { name: 'John Doe', email: 'john.updated@example.com' }]
)
console.log('\nUpdate Results:')
updateResults.forEach((result, index) => {
console.log(`Result ${index + 1}:`)
console.log(` Success: ${result.success}`)
if (!result.success) {
console.log(` Error: ${result.error}`)
}
})
// Retrieve updated data from all memory augmentations
console.log('\n=== Retrieving Updated Data ===')
const retrieveUpdatedResults = await augmentationPipeline.executeMemoryPipeline(
'retrieveData',
['user123']
)
console.log('\nRetrieve Updated Results:')
retrieveUpdatedResults.forEach((result, index) => {
console.log(`Result ${index + 1}:`)
console.log(` Success: ${result.success}`)
if (result.success) {
console.log(` Data: ${JSON.stringify(result.data)}`)
} else {
console.log(` Error: ${result.error}`)
}
})
// Store additional data
console.log('\n=== Storing Additional Data ===')
await augmentationPipeline.executeMemoryPipeline(
'storeData',
['user456', { name: 'Jane Smith', email: 'jane@example.com' }]
)
// List all keys
console.log('\n=== Listing All Keys ===')
const listResults = await augmentationPipeline.executeMemoryPipeline(
'listDataKeys',
[]
)
console.log('\nList Results:')
listResults.forEach((result, index) => {
console.log(`Result ${index + 1}:`)
console.log(` Success: ${result.success}`)
if (result.success) {
console.log(` Keys: ${result.data.join(', ')}`)
} else {
console.log(` Error: ${result.error}`)
}
})
// Use the WebSocket-Memory augmentation directly
console.log('\n=== Using WebSocket-Memory Augmentation ===')
const connection = await webSocketMemory.connectWebSocket('wss://example.com/storage')
console.log('Connection established:', connection)
// Store data through WebSocket
console.log('\n=== Storing Data Through WebSocket ===')
const wsStoreResult = await webSocketMemory.storeData(
'wsUser123',
{ name: 'WebSocket User', email: 'ws@example.com' },
{ connectionId: connection.connectionId }
)
console.log('WebSocket Store Result:', wsStoreResult)
// Retrieve data through WebSocket
console.log('\n=== Retrieving Data Through WebSocket ===')
const wsRetrieveResult = await webSocketMemory.retrieveData(
'wsUser123',
{ connectionId: connection.connectionId }
)
console.log('WebSocket Retrieve Result:', wsRetrieveResult)
// Delete data from all memory augmentations
console.log('\n=== Deleting Data ===')
const deleteResults = await augmentationPipeline.executeMemoryPipeline(
'deleteData',
['user123']
)
console.log('\nDelete Results:')
deleteResults.forEach((result, index) => {
console.log(`Result ${index + 1}:`)
console.log(` Success: ${result.success}`)
if (!result.success) {
console.log(` Error: ${result.error}`)
}
})
// Shut down all registered augmentations
console.log('\n=== Shutting Down Augmentations ===')
await augmentationPipeline.shutDown()
console.log('\n=== Example Complete ===')
} catch (error) {
console.error('Error in memory augmentation example:', error)
}
}
// Run the example
main()

View file

@ -1,210 +0,0 @@
/**
* WebSocket Augmentation Example
*
* This example demonstrates how to create and register a WebSocket-supporting augmentation.
*/
import {
augmentationPipeline,
IAugmentation,
IWebSocketSupport,
IWebSocketCognitionAugmentation,
AugmentationResponse,
BrainyAugmentations
} from '../index.js'
/**
* Example WebSocket Augmentation
*/
class SimpleWebSocketAugmentation implements IWebSocketSupport {
readonly name = 'simple-websocket'
readonly description = 'A simple WebSocket augmentation for demonstration'
async initialize(): Promise<void> {
console.log('Initializing SimpleWebSocketAugmentation')
}
async shutDown(): Promise<void> {
console.log('Shutting down SimpleWebSocketAugmentation')
}
async getStatus(): Promise<'active' | 'inactive' | 'error'> {
return 'active'
}
async connectWebSocket(url: string, protocols?: string | string[]): Promise<{
connectionId: string;
url: string;
status: 'connected' | 'disconnected' | 'error'
}> {
console.log(`Connecting to WebSocket at ${url}`)
return {
connectionId: 'ws-1',
url,
status: 'connected'
}
}
async sendWebSocketMessage(connectionId: string, data: unknown): Promise<void> {
console.log(`Sending message to WebSocket ${connectionId}:`, data)
}
async onWebSocketMessage(connectionId: string, callback: (data: unknown) => void): Promise<void> {
console.log(`Registering callback for WebSocket ${connectionId}`)
// In a real implementation, this would set up a listener
}
async closeWebSocket(connectionId: string, code?: number, reason?: string): Promise<void> {
console.log(`Closing WebSocket ${connectionId}`)
}
}
/**
* Example Combined WebSocket and Cognition Augmentation
*/
class WebSocketCognitionAugmentation implements IWebSocketCognitionAugmentation {
readonly name = 'websocket-cognition'
readonly description = 'A combined WebSocket and Cognition augmentation for demonstration'
async initialize(): Promise<void> {
console.log('Initializing WebSocketCognitionAugmentation')
}
async shutDown(): Promise<void> {
console.log('Shutting down WebSocketCognitionAugmentation')
}
async getStatus(): Promise<'active' | 'inactive' | 'error'> {
return 'active'
}
// WebSocket methods
async connectWebSocket(url: string, protocols?: string | string[]): Promise<{
connectionId: string;
url: string;
status: 'connected' | 'disconnected' | 'error'
}> {
console.log(`WebSocketCognition connecting to WebSocket at ${url}`)
return {
connectionId: 'ws-cognition-1',
url,
status: 'connected'
}
}
async sendWebSocketMessage(connectionId: string, data: unknown): Promise<void> {
console.log(`WebSocketCognition sending message to WebSocket ${connectionId}:`, data)
}
async onWebSocketMessage(connectionId: string, callback: (data: unknown) => void): Promise<void> {
console.log(`WebSocketCognition registering callback for WebSocket ${connectionId}`)
}
async closeWebSocket(connectionId: string, code?: number, reason?: string): Promise<void> {
console.log(`WebSocketCognition closing WebSocket ${connectionId}`)
}
// Cognition methods
async reason(
query: string,
context?: Record<string, unknown>
): Promise<AugmentationResponse<{ inference: string; confidence: number }>> {
console.log(`WebSocketCognition reasoning about: ${query}`)
console.log('Context:', context)
return {
success: true,
data: {
inference: `WebSocket-enabled inference about: ${query}`,
confidence: 0.85
}
}
}
async infer(
dataSubset: Record<string, unknown>
): Promise<AugmentationResponse<Record<string, unknown>>> {
return {
success: true,
data: {
result: `WebSocket-enabled inference from data: ${JSON.stringify(dataSubset)}`
}
}
}
async executeLogic(
ruleId: string,
input: Record<string, unknown>
): Promise<AugmentationResponse<boolean>> {
return {
success: true,
data: true
}
}
}
/**
* Main function to demonstrate the WebSocket augmentation
*/
async function main() {
try {
console.log('=== WebSocket Augmentation Example ===')
// Create augmentation instances
const simpleWebSocket = new SimpleWebSocketAugmentation()
const webSocketCognition = new WebSocketCognitionAugmentation()
// Register augmentations with the pipeline
augmentationPipeline
.register(simpleWebSocket)
.register(webSocketCognition)
// Initialize all registered augmentations
console.log('\n=== Initializing Augmentations ===')
await augmentationPipeline.initialize()
// Get all WebSocket-supporting augmentations
console.log('\n=== WebSocket Augmentations ===')
const webSocketAugmentations = augmentationPipeline.getWebSocketAugmentations()
console.log(`Found ${webSocketAugmentations.length} WebSocket augmentations:`)
webSocketAugmentations.forEach(aug => {
console.log(`- ${aug.name}: ${aug.description}`)
})
// Use the simple WebSocket augmentation
console.log('\n=== Using Simple WebSocket Augmentation ===')
const connection = await simpleWebSocket.connectWebSocket('wss://example.com')
console.log('Connection established:', connection)
await simpleWebSocket.sendWebSocketMessage(connection.connectionId, { message: 'Hello, WebSocket!' })
// Use the combined WebSocket and Cognition augmentation
console.log('\n=== Using Combined WebSocket-Cognition Augmentation ===')
const wsConnection = await webSocketCognition.connectWebSocket('wss://example.com/cognition')
console.log('Connection established:', wsConnection)
await webSocketCognition.sendWebSocketMessage(wsConnection.connectionId, { message: 'Hello from cognition!' })
// Execute a cognition method on the combined augmentation
console.log('\n=== Executing Cognition Method on Combined Augmentation ===')
const reasoningResult = await webSocketCognition.reason('What is the meaning of life?', { context: 'philosophical' })
console.log('Reasoning result:', reasoningResult)
// Use the cognition pipeline with the combined augmentation
console.log('\n=== Executing Cognition Pipeline ===')
const pipelineResults = await augmentationPipeline.executeCognitionPipeline(
'reason',
['What is the capital of France?', { additionalContext: 'geography' }]
)
console.log('Pipeline results:', pipelineResults)
// Shut down all registered augmentations
console.log('\n=== Shutting Down Augmentations ===')
await augmentationPipeline.shutDown()
console.log('\n=== Example Complete ===')
} catch (error) {
console.error('Error in WebSocket augmentation example:', error)
}
}
// Run the example
main()

View file

@ -22,6 +22,20 @@ export {
dotProductDistance
}
// Export embedding functionality
import {
SimpleEmbedding,
UniversalSentenceEncoder,
createEmbeddingFunction,
defaultEmbeddingFunction
} from './utils/embedding.js'
export {
SimpleEmbedding,
UniversalSentenceEncoder,
createEmbeddingFunction,
defaultEmbeddingFunction
}
// Export storage adapters
import {
OPFSStorage,

View file

@ -20,11 +20,11 @@ type WebSocketConnection = {
}
type DataCallback<T> = (data: T) => void
export type AugmentationResponse<T> = Promise<{
export type AugmentationResponse<T> = {
success: boolean
data: T
error?: string
}>
}
/**
* Base interface for all Brainy augmentations.