fix: export ImportManager and add getStats() convenience method
Resolves API accessibility issues reported by Brain Cloud Studio team: 1. Export ImportManager and createImportManager - ImportManager class was fully implemented but not exported - Consumers can now access AI-powered import features - Includes ImportOptions and ImportResult types 2. Add brain.getStats() convenience method - Documentation showed getStats() as top-level method - Implementation had it nested under brain.counts.getStats() - Added convenience method that delegates to counts API - Maintains backward compatibility 3. Update API documentation - Corrected getStats() signature and return type - Added comprehensive ImportManager documentation - Included examples for all import patterns These changes expose existing, tested functionality without modifying core behavior. All tests pass.
This commit is contained in:
parent
544c9f8a5e
commit
06b3bc77e1
3 changed files with 127 additions and 8 deletions
|
|
@ -775,14 +775,120 @@ const exported = await data.export({
|
|||
|
||||
---
|
||||
|
||||
### `async getStats(): Promise<StorageStats>`
|
||||
Gets storage statistics.
|
||||
### `getStats(): StatsResult`
|
||||
Gets complete statistics about entities and relationships.
|
||||
|
||||
**Returns:**
|
||||
- `entities` - Entity count
|
||||
- `relations` - Relationship count
|
||||
- `storageSize` - Storage size in bytes
|
||||
- `vectorDimensions` - Embedding dimensions
|
||||
```typescript
|
||||
{
|
||||
entities: {
|
||||
total: number
|
||||
byType: Record<string, number>
|
||||
}
|
||||
relationships: {
|
||||
totalRelationships: number
|
||||
byType: Record<string, number>
|
||||
}
|
||||
density: number // relationships per entity
|
||||
}
|
||||
```
|
||||
|
||||
**Example:**
|
||||
```typescript
|
||||
const stats = brain.getStats()
|
||||
console.log(`Total entities: ${stats.entities.total}`)
|
||||
console.log(`Total relationships: ${stats.relationships.totalRelationships}`)
|
||||
console.log(`Graph density: ${stats.density.toFixed(2)}`)
|
||||
```
|
||||
|
||||
**Note:** For more granular counting operations, see the `brain.counts` API below.
|
||||
|
||||
---
|
||||
|
||||
## Import API
|
||||
|
||||
### `createImportManager(brain: Brainy): ImportManager`
|
||||
Creates an import manager for intelligent data import.
|
||||
|
||||
**Example:**
|
||||
```typescript
|
||||
import { Brainy, createImportManager } from '@soulcraft/brainy'
|
||||
|
||||
const brain = new Brainy({ preset: 'memory' })
|
||||
await brain.init()
|
||||
|
||||
const importer = createImportManager(brain)
|
||||
await importer.init()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `async ImportManager.import(source, options?): Promise<ImportResult>`
|
||||
Import data from various sources with AI-powered entity detection.
|
||||
|
||||
**Parameters:**
|
||||
- `source` - String, Buffer, array, or object to import
|
||||
- `options.source` - 'data' | 'file' | 'url' | 'auto' (default: 'auto')
|
||||
- `options.format` - 'json' | 'csv' | 'text' | 'yaml' | 'auto' (default: 'auto')
|
||||
- `options.batchSize` - Batch size for processing (default: 50)
|
||||
- `options.autoDetect` - Auto-detect entity types (default: true)
|
||||
- `options.typeHint` - Suggested entity type
|
||||
- `options.extractRelationships` - Extract relationships (default: true)
|
||||
- `options.csvDelimiter` - CSV delimiter character
|
||||
- `options.csvHeaders` - CSV has headers (default: true)
|
||||
- `options.parallel` - Process in parallel (default: true)
|
||||
- `options.maxConcurrency` - Max concurrent operations
|
||||
|
||||
**Returns:**
|
||||
```typescript
|
||||
{
|
||||
success: boolean
|
||||
nouns: string[] // IDs of imported entities
|
||||
verbs: string[] // IDs of created relationships
|
||||
errors: string[]
|
||||
stats: {
|
||||
total: number
|
||||
imported: number
|
||||
failed: number
|
||||
relationships: number
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Examples:**
|
||||
|
||||
```typescript
|
||||
// Import from CSV file
|
||||
const result = await importer.importFile('./data.csv', {
|
||||
format: 'csv',
|
||||
extractRelationships: true
|
||||
})
|
||||
|
||||
// Import from URL
|
||||
const result = await importer.importUrl('https://api.example.com/data.json')
|
||||
|
||||
// Import array of objects
|
||||
const data = [
|
||||
{ name: 'Alice', role: 'Developer' },
|
||||
{ name: 'Bob', role: 'Designer' }
|
||||
]
|
||||
const result = await importer.import(data, {
|
||||
typeHint: NounType.Person,
|
||||
extractRelationships: true
|
||||
})
|
||||
|
||||
console.log(`Imported ${result.stats.imported}/${result.stats.total} items`)
|
||||
console.log(`Created ${result.stats.relationships} relationships`)
|
||||
```
|
||||
|
||||
**Features:**
|
||||
- 🧠 **AI Entity Detection** - Auto-detect entity types from data
|
||||
- 🔗 **Relationship Extraction** - Discover connections automatically
|
||||
- 📊 **Multi-Format Support** - CSV, JSON, YAML, text files
|
||||
- 🚀 **Batch Processing** - Efficient handling of large datasets
|
||||
- 💡 **Neural Analysis** - Confidence scoring and insights
|
||||
- 🎯 **Smart CSV Parsing** - Auto-delimiter detection
|
||||
- 🌐 **URL Imports** - Direct import from web sources
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue