fix: correct typo in README major updates section
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
d2ddb9199e
commit
1a4f035ffc
22 changed files with 4423 additions and 142 deletions
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
import { HNSWNoun, GraphVerb } from '../../coreTypes.js'
|
||||
import { createModuleLogger } from '../../utils/logger.js'
|
||||
import { getDirectoryPath } from '../baseStorage.js'
|
||||
|
||||
const logger = createModuleLogger('OptimizedS3Search')
|
||||
|
||||
|
|
@ -70,7 +71,7 @@ export class OptimizedS3Search {
|
|||
|
||||
try {
|
||||
// List noun objects with pagination
|
||||
const listResult = await this.storage.listObjectKeys('nouns/', limit * 2, cursor)
|
||||
const listResult = await this.storage.listObjectKeys(`${getDirectoryPath('noun', 'vector')}/`, limit * 2, cursor)
|
||||
|
||||
if (!listResult.keys.length) {
|
||||
return {
|
||||
|
|
@ -141,7 +142,7 @@ export class OptimizedS3Search {
|
|||
|
||||
try {
|
||||
// List verb objects with pagination
|
||||
const listResult = await this.storage.listObjectKeys('verbs/', limit * 2, cursor)
|
||||
const listResult = await this.storage.listObjectKeys(`${getDirectoryPath('verb', 'vector')}/`, limit * 2, cursor)
|
||||
|
||||
if (!listResult.keys.length) {
|
||||
return {
|
||||
|
|
@ -163,7 +164,7 @@ export class OptimizedS3Search {
|
|||
if (!verbData) return null
|
||||
|
||||
// Get metadata
|
||||
const verbId = key.replace('verbs/', '').replace('.json', '')
|
||||
const verbId = key.replace(`${getDirectoryPath('verb', 'vector')}/`, '').replace('.json', '')
|
||||
const metadata = await this.storage.getMetadata(verbId, 'verb')
|
||||
|
||||
// Combine into GraphVerb
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ import {
|
|||
METADATA_DIR,
|
||||
INDEX_DIR,
|
||||
SYSTEM_DIR,
|
||||
STATISTICS_KEY
|
||||
STATISTICS_KEY,
|
||||
getDirectoryPath
|
||||
} from '../baseStorage.js'
|
||||
import { StorageCompatibilityLayer, StoragePaths } from '../backwardCompatibility.js'
|
||||
import {
|
||||
|
|
@ -80,7 +81,8 @@ export class S3CompatibleStorage extends BaseStorage {
|
|||
// Prefixes for different types of data
|
||||
private nounPrefix: string
|
||||
private verbPrefix: string
|
||||
private metadataPrefix: string
|
||||
private metadataPrefix: string // Noun metadata
|
||||
private verbMetadataPrefix: string // Verb metadata
|
||||
private indexPrefix: string // Legacy - for backward compatibility
|
||||
private systemPrefix: string // New location for system data
|
||||
private useDualWrite: boolean = true // Write to both locations during migration
|
||||
|
|
@ -142,10 +144,11 @@ export class S3CompatibleStorage extends BaseStorage {
|
|||
options.operationConfig
|
||||
)
|
||||
|
||||
// Set up prefixes for different types of data
|
||||
this.nounPrefix = `${NOUNS_DIR}/`
|
||||
this.verbPrefix = `${VERBS_DIR}/`
|
||||
this.metadataPrefix = `${METADATA_DIR}/`
|
||||
// Set up prefixes for different types of data using new entity-based structure
|
||||
this.nounPrefix = `${getDirectoryPath('noun', 'vector')}/`
|
||||
this.verbPrefix = `${getDirectoryPath('verb', 'vector')}/`
|
||||
this.metadataPrefix = `${getDirectoryPath('noun', 'metadata')}/` // Noun metadata
|
||||
this.verbMetadataPrefix = `${getDirectoryPath('verb', 'metadata')}/` // Verb metadata
|
||||
this.indexPrefix = `${INDEX_DIR}/` // Legacy
|
||||
this.systemPrefix = `${SYSTEM_DIR}/` // New
|
||||
|
||||
|
|
@ -1283,7 +1286,7 @@ export class S3CompatibleStorage extends BaseStorage {
|
|||
// Import the PutObjectCommand only when needed
|
||||
const { PutObjectCommand } = await import('@aws-sdk/client-s3')
|
||||
|
||||
const key = `verb-metadata/${id}.json`
|
||||
const key = `${this.verbMetadataPrefix}${id}.json`
|
||||
const body = JSON.stringify(metadata, null, 2)
|
||||
|
||||
this.logger.trace(`Saving verb metadata for ${id} to key: ${key}`)
|
||||
|
|
@ -1315,7 +1318,7 @@ export class S3CompatibleStorage extends BaseStorage {
|
|||
// Import the GetObjectCommand only when needed
|
||||
const { GetObjectCommand } = await import('@aws-sdk/client-s3')
|
||||
|
||||
const key = `verb-metadata/${id}.json`
|
||||
const key = `${this.verbMetadataPrefix}${id}.json`
|
||||
this.logger.trace(`Getting verb metadata for ${id} from key: ${key}`)
|
||||
|
||||
// Try to get the verb metadata
|
||||
|
|
@ -1373,7 +1376,7 @@ export class S3CompatibleStorage extends BaseStorage {
|
|||
// Import the PutObjectCommand only when needed
|
||||
const { PutObjectCommand } = await import('@aws-sdk/client-s3')
|
||||
|
||||
const key = `noun-metadata/${id}.json`
|
||||
const key = `${this.metadataPrefix}${id}.json`
|
||||
const body = JSON.stringify(metadata, null, 2)
|
||||
|
||||
this.logger.trace(`Saving noun metadata for ${id} to key: ${key}`)
|
||||
|
|
@ -1405,7 +1408,7 @@ export class S3CompatibleStorage extends BaseStorage {
|
|||
// Import the GetObjectCommand only when needed
|
||||
const { GetObjectCommand } = await import('@aws-sdk/client-s3')
|
||||
|
||||
const key = `noun-metadata/${id}.json`
|
||||
const key = `${this.metadataPrefix}${id}.json`
|
||||
this.logger.trace(`Getting noun metadata for ${id} from key: ${key}`)
|
||||
|
||||
// Try to get the noun metadata
|
||||
|
|
@ -1569,9 +1572,12 @@ export class S3CompatibleStorage extends BaseStorage {
|
|||
// Delete all objects in the verbs directory
|
||||
await deleteObjectsWithPrefix(this.verbPrefix)
|
||||
|
||||
// Delete all objects in the metadata directory
|
||||
// Delete all objects in the noun metadata directory
|
||||
await deleteObjectsWithPrefix(this.metadataPrefix)
|
||||
|
||||
// Delete all objects in the verb metadata directory
|
||||
await deleteObjectsWithPrefix(this.verbMetadataPrefix)
|
||||
|
||||
// Delete all objects in the index directory
|
||||
await deleteObjectsWithPrefix(this.indexPrefix)
|
||||
|
||||
|
|
@ -1659,17 +1665,19 @@ export class S3CompatibleStorage extends BaseStorage {
|
|||
// Calculate size and count for each directory
|
||||
const nounsResult = await calculateSizeAndCount(this.nounPrefix)
|
||||
const verbsResult = await calculateSizeAndCount(this.verbPrefix)
|
||||
const metadataResult = await calculateSizeAndCount(this.metadataPrefix)
|
||||
const nounMetadataResult = await calculateSizeAndCount(this.metadataPrefix)
|
||||
const verbMetadataResult = await calculateSizeAndCount(this.verbMetadataPrefix)
|
||||
const indexResult = await calculateSizeAndCount(this.indexPrefix)
|
||||
|
||||
totalSize =
|
||||
nounsResult.size +
|
||||
verbsResult.size +
|
||||
metadataResult.size +
|
||||
nounMetadataResult.size +
|
||||
verbMetadataResult.size +
|
||||
indexResult.size
|
||||
nodeCount = nounsResult.count
|
||||
edgeCount = verbsResult.count
|
||||
metadataCount = metadataResult.count
|
||||
metadataCount = nounMetadataResult.count + verbMetadataResult.count
|
||||
|
||||
// Ensure we have a minimum size if we have objects
|
||||
if (
|
||||
|
|
|
|||
|
|
@ -7,17 +7,51 @@ import { GraphVerb, HNSWNoun, HNSWVerb, StatisticsData } from '../coreTypes.js'
|
|||
import { BaseStorageAdapter } from './adapters/baseStorageAdapter.js'
|
||||
|
||||
// Common directory/prefix names
|
||||
export const NOUNS_DIR = 'nouns'
|
||||
export const VERBS_DIR = 'verbs'
|
||||
export const METADATA_DIR = 'metadata'
|
||||
export const NOUN_METADATA_DIR = 'noun-metadata'
|
||||
export const VERB_METADATA_DIR = 'verb-metadata'
|
||||
// Option A: Entity-Based Directory Structure
|
||||
export const ENTITIES_DIR = 'entities'
|
||||
export const NOUNS_VECTOR_DIR = 'entities/nouns/vectors'
|
||||
export const NOUNS_METADATA_DIR = 'entities/nouns/metadata'
|
||||
export const VERBS_VECTOR_DIR = 'entities/verbs/vectors'
|
||||
export const VERBS_METADATA_DIR = 'entities/verbs/metadata'
|
||||
export const INDEXES_DIR = 'indexes'
|
||||
export const METADATA_INDEX_DIR = 'indexes/metadata'
|
||||
|
||||
// Legacy paths - kept for backward compatibility during migration
|
||||
export const NOUNS_DIR = 'nouns' // Legacy: now maps to entities/nouns/vectors
|
||||
export const VERBS_DIR = 'verbs' // Legacy: now maps to entities/verbs/vectors
|
||||
export const METADATA_DIR = 'metadata' // Legacy: now maps to entities/nouns/metadata
|
||||
export const NOUN_METADATA_DIR = 'noun-metadata' // Legacy: now maps to entities/nouns/metadata
|
||||
export const VERB_METADATA_DIR = 'verb-metadata' // Legacy: now maps to entities/verbs/metadata
|
||||
export const INDEX_DIR = 'index' // Legacy - kept for backward compatibility
|
||||
export const SYSTEM_DIR = '_system' // New location for system data
|
||||
export const SYSTEM_DIR = '_system' // System config & metadata indexes
|
||||
export const STATISTICS_KEY = 'statistics'
|
||||
|
||||
// Migration version to track compatibility
|
||||
export const STORAGE_SCHEMA_VERSION = 2 // Increment when making breaking changes
|
||||
export const STORAGE_SCHEMA_VERSION = 3 // v3: Entity-Based Directory Structure (Option A)
|
||||
|
||||
// Configuration flag to enable new directory structure
|
||||
export const USE_ENTITY_BASED_STRUCTURE = true // Set to true to use Option A structure
|
||||
|
||||
/**
|
||||
* Get the appropriate directory path based on configuration
|
||||
*/
|
||||
export function getDirectoryPath(entityType: 'noun' | 'verb', dataType: 'vector' | 'metadata'): string {
|
||||
if (USE_ENTITY_BASED_STRUCTURE) {
|
||||
// Option A: Entity-Based Structure
|
||||
if (entityType === 'noun') {
|
||||
return dataType === 'vector' ? NOUNS_VECTOR_DIR : NOUNS_METADATA_DIR
|
||||
} else {
|
||||
return dataType === 'vector' ? VERBS_VECTOR_DIR : VERBS_METADATA_DIR
|
||||
}
|
||||
} else {
|
||||
// Legacy structure
|
||||
if (entityType === 'noun') {
|
||||
return dataType === 'vector' ? NOUNS_DIR : METADATA_DIR
|
||||
} else {
|
||||
return dataType === 'vector' ? VERBS_DIR : VERB_METADATA_DIR
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Base storage adapter that implements common functionality
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue