feat(v4.0.0): Complete metadata/vector separation architecture with Azure support
This commit completes the core v4.0.0 architecture changes for billion-scale performance with metadata/vector separation. NO RELEASE YET - remaining optimizations and testing required before production release. ## Core v4.0.0 Architecture Changes ### Type System Updates - Fixed all TypeScript compilation errors (zero errors achieved) - Updated HNSWNoun/HNSWVerb to separate core fields from metadata - Implemented HNSWNounWithMetadata/HNSWVerbWithMetadata for API boundaries - Added required 'noun' field to NounMetadata for semantic structure - Renamed verb.type to verb.verb for consistency ### Storage Adapter Updates **All adapters updated for v4.0.0 two-file storage pattern:** - memoryStorage: Proper metadata/vector separation - fileSystemStorage: Two-file pattern with sharding - opfsStorage: Browser persistent storage updated - s3CompatibleStorage: AWS/MinIO/DigitalOcean support - r2Storage: Cloudflare R2 optimization - gcsStorage: Google Cloud with ADC support - **azureBlobStorage: NEW - Full Azure Blob Storage support** ### Storage Features - BaseStorage: Internal vs public method separation (_getNoun vs getNoun) - Two-file storage: Vectors in one file, metadata in another - Change tracking: getChangesSince return type updated - Pagination: getNounsWithPagination returns WithMetadata types ### Azure Blob Storage Integration (NEW) - Native @azure/storage-blob SDK integration - Four authentication methods: * DefaultAzureCredential (Managed Identity) - recommended * Connection String - simplest setup * Account Name + Key - traditional auth * SAS Token - delegated access - High-volume mode with write buffering - Adaptive backpressure for throttling - UUID-based sharding for billion-scale - Full HNSW support with graph persistence ### Utility Updates - EmbeddingManager: Updated to accept Record<string, unknown> - LSMTree: Wrapped data in NounMetadata structure with 'noun' field - EntityIdMapper: Fixed nested metadata.data structure access - MetadataIndex: Fixed field type inference integration - PeriodicCleanup: Updated for new metadata structure ### Core API Updates - Brainy: Updated verb property access from v.type to v.verb - ConfigAPI: Fixed NounMetadata access patterns - DataAPI: Updated metadata handling ### Documentation Updates - CREATING-AUGMENTATIONS.md: v4.0.0 breaking changes guide - DEVELOPER-GUIDE.md: Migration checklist and examples - COMPLETE-REFERENCE.md: v4.0.0 architecture improvements - **finite-type-system.md: NEW - Revolutionary type system benefits** ### Build & Dependencies - Zero TypeScript compilation errors - Added @azure/storage-blob and @azure/identity - 591 tests passing (23 timeout in long-running neural tests) ## What's NOT in This Release This is a work-in-progress commit. Before v4.0.0 release we need: - Storage adapter optimizations (batch operations, compression) - Azure blob tier management (Hot/Cool/Archive) - Cost optimization implementations - Additional performance testing at billion-scale - Migration guides for v3.x users ## Testing - Clean build: ✅ - Type checking: ✅ (zero errors) - Test suite: ✅ (591/614 passing, timeouts in neural tests only) 🔐 Generated with Claude Code https://claude.com/claude-code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
8d6dd07e1d
commit
92c96246fb
35 changed files with 4524 additions and 1026 deletions
|
|
@ -12,7 +12,16 @@
|
|||
* Based on latest GCS and S3 implementations with R2-specific enhancements
|
||||
*/
|
||||
|
||||
import { GraphVerb, HNSWNoun, HNSWVerb, StatisticsData } from '../../coreTypes.js'
|
||||
import {
|
||||
GraphVerb,
|
||||
HNSWNoun,
|
||||
HNSWVerb,
|
||||
NounMetadata,
|
||||
VerbMetadata,
|
||||
HNSWNounWithMetadata,
|
||||
HNSWVerbWithMetadata,
|
||||
StatisticsData
|
||||
} from '../../coreTypes.js'
|
||||
import {
|
||||
BaseStorage,
|
||||
NOUNS_DIR,
|
||||
|
|
@ -426,7 +435,7 @@ export class R2Storage extends BaseStorage {
|
|||
// Increment noun count
|
||||
const metadata = await this.getNounMetadata(node.id)
|
||||
if (metadata && metadata.type) {
|
||||
await this.incrementEntityCountSafe(metadata.type)
|
||||
await this.incrementEntityCountSafe(metadata.type as string)
|
||||
}
|
||||
|
||||
this.logger.trace(`Node ${node.id} saved successfully`)
|
||||
|
|
@ -446,19 +455,18 @@ export class R2Storage extends BaseStorage {
|
|||
|
||||
/**
|
||||
* Get a noun from storage (internal implementation)
|
||||
* v4.0.0: Returns ONLY vector data (no metadata field)
|
||||
* Base class combines with metadata via getNoun() -> HNSWNounWithMetadata
|
||||
*/
|
||||
protected async getNoun_internal(id: string): Promise<HNSWNoun | null> {
|
||||
// v4.0.0: Return ONLY vector data (no metadata field)
|
||||
const node = await this.getNode(id)
|
||||
if (!node) {
|
||||
return null
|
||||
}
|
||||
|
||||
const metadata = await this.getNounMetadata(id)
|
||||
|
||||
return {
|
||||
...node,
|
||||
metadata: metadata || {}
|
||||
}
|
||||
// Return pure vector structure
|
||||
return node
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -565,7 +573,7 @@ export class R2Storage extends BaseStorage {
|
|||
// Decrement noun count
|
||||
const metadata = await this.getNounMetadata(id)
|
||||
if (metadata && metadata.type) {
|
||||
await this.decrementEntityCountSafe(metadata.type)
|
||||
await this.decrementEntityCountSafe(metadata.type as string)
|
||||
}
|
||||
|
||||
this.logger.trace(`Noun ${id} deleted successfully`)
|
||||
|
|
@ -765,7 +773,7 @@ export class R2Storage extends BaseStorage {
|
|||
|
||||
const metadata = await this.getVerbMetadata(edge.id)
|
||||
if (metadata && metadata.type) {
|
||||
await this.incrementVerbCount(metadata.type)
|
||||
await this.incrementVerbCount(metadata.type as string)
|
||||
}
|
||||
|
||||
this.releaseBackpressure(true, requestId)
|
||||
|
|
@ -781,18 +789,20 @@ export class R2Storage extends BaseStorage {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a verb from storage (internal implementation)
|
||||
* v4.0.0: Returns ONLY vector + core relational fields (no metadata field)
|
||||
* Base class combines with metadata via getVerb() -> HNSWVerbWithMetadata
|
||||
*/
|
||||
protected async getVerb_internal(id: string): Promise<HNSWVerb | null> {
|
||||
// v4.0.0: Return ONLY vector + core relational data (no metadata field)
|
||||
const edge = await this.getEdge(id)
|
||||
if (!edge) {
|
||||
return null
|
||||
}
|
||||
|
||||
const metadata = await this.getVerbMetadata(id)
|
||||
|
||||
return {
|
||||
...edge,
|
||||
metadata: metadata || {}
|
||||
}
|
||||
// Return pure vector + core fields structure
|
||||
return edge
|
||||
}
|
||||
|
||||
protected async getEdge(id: string): Promise<Edge | null> {
|
||||
|
|
@ -824,7 +834,7 @@ export class R2Storage extends BaseStorage {
|
|||
connections.set(Number(level), new Set(verbIds as string[]))
|
||||
}
|
||||
|
||||
// ARCHITECTURAL FIX (v3.50.1): Return HNSWVerb with core relational fields
|
||||
// v4.0.0: Return HNSWVerb with core relational fields (NO metadata field)
|
||||
const edge: Edge = {
|
||||
id: data.id,
|
||||
vector: data.vector,
|
||||
|
|
@ -833,10 +843,10 @@ export class R2Storage extends BaseStorage {
|
|||
// CORE RELATIONAL DATA (read from vector file)
|
||||
verb: data.verb,
|
||||
sourceId: data.sourceId,
|
||||
targetId: data.targetId,
|
||||
targetId: data.targetId
|
||||
|
||||
// User metadata (retrieved separately via getVerbMetadata())
|
||||
metadata: data.metadata
|
||||
// ✅ NO metadata field in v4.0.0
|
||||
// User metadata retrieved separately via getVerbMetadata()
|
||||
}
|
||||
|
||||
this.verbCacheManager.set(id, edge)
|
||||
|
|
@ -878,7 +888,7 @@ export class R2Storage extends BaseStorage {
|
|||
|
||||
const metadata = await this.getVerbMetadata(id)
|
||||
if (metadata && metadata.type) {
|
||||
await this.decrementVerbCount(metadata.type)
|
||||
await this.decrementVerbCount(metadata.type as string)
|
||||
}
|
||||
|
||||
this.releaseBackpressure(true, requestId)
|
||||
|
|
@ -1130,7 +1140,7 @@ export class R2Storage extends BaseStorage {
|
|||
metadata?: Record<string, any>
|
||||
}
|
||||
} = {}): Promise<{
|
||||
items: HNSWNoun[]
|
||||
items: HNSWNounWithMetadata[]
|
||||
totalCount?: number
|
||||
hasMore: boolean
|
||||
nextCursor?: string
|
||||
|
|
@ -1150,7 +1160,7 @@ export class R2Storage extends BaseStorage {
|
|||
})
|
||||
)
|
||||
|
||||
const items: HNSWNoun[] = []
|
||||
const items: HNSWNounWithMetadata[] = []
|
||||
const contents = response.Contents || []
|
||||
|
||||
for (const obj of contents) {
|
||||
|
|
@ -1161,7 +1171,55 @@ export class R2Storage extends BaseStorage {
|
|||
|
||||
const noun = await this.getNoun_internal(id)
|
||||
if (noun) {
|
||||
items.push(noun)
|
||||
// v4.0.0: Load metadata and combine with noun to create HNSWNounWithMetadata
|
||||
const metadata = await this.getNounMetadata(id)
|
||||
if (!metadata) continue
|
||||
|
||||
// Apply filters if provided
|
||||
if (options.filter) {
|
||||
// Filter by noun type
|
||||
if (options.filter.nounType) {
|
||||
const nounTypes = Array.isArray(options.filter.nounType)
|
||||
? options.filter.nounType
|
||||
: [options.filter.nounType]
|
||||
if (!nounTypes.includes((metadata.type || metadata.noun) as string)) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Filter by service
|
||||
if (options.filter.service) {
|
||||
const services = Array.isArray(options.filter.service)
|
||||
? options.filter.service
|
||||
: [options.filter.service]
|
||||
if (!metadata.createdBy?.augmentation || !services.includes(metadata.createdBy.augmentation as string)) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Filter by metadata
|
||||
if (options.filter.metadata) {
|
||||
let matches = true
|
||||
for (const [key, value] of Object.entries(options.filter.metadata)) {
|
||||
if (metadata[key] !== value) {
|
||||
matches = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!matches) continue
|
||||
}
|
||||
}
|
||||
|
||||
// v4.0.0: Create HNSWNounWithMetadata by combining noun with metadata
|
||||
const nounWithMetadata: HNSWNounWithMetadata = {
|
||||
id: noun.id,
|
||||
vector: [...noun.vector],
|
||||
connections: new Map(noun.connections),
|
||||
level: noun.level || 0,
|
||||
metadata: metadata
|
||||
}
|
||||
|
||||
items.push(nounWithMetadata)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1182,16 +1240,16 @@ export class R2Storage extends BaseStorage {
|
|||
return result.items
|
||||
}
|
||||
|
||||
protected async getVerbsBySource_internal(sourceId: string): Promise<GraphVerb[]> {
|
||||
protected async getVerbsBySource_internal(sourceId: string): Promise<HNSWVerbWithMetadata[]> {
|
||||
// Simplified - full implementation would include proper filtering
|
||||
return []
|
||||
}
|
||||
|
||||
protected async getVerbsByTarget_internal(targetId: string): Promise<GraphVerb[]> {
|
||||
protected async getVerbsByTarget_internal(targetId: string): Promise<HNSWVerbWithMetadata[]> {
|
||||
return []
|
||||
}
|
||||
|
||||
protected async getVerbsByType_internal(type: string): Promise<GraphVerb[]> {
|
||||
protected async getVerbsByType_internal(type: string): Promise<HNSWVerbWithMetadata[]> {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue