fix(src/brainyData): enforce consistent formatting and improve code readability

Applied consistent formatting adjustments across `src/brainyData.ts`, including line breaks, parentheses, and object destructuring. These changes enhance code readability, maintainability, and alignment with the project's style guidelines without altering functionality.
This commit is contained in:
David Snelling 2025-06-26 10:56:29 -07:00
parent 95be23362a
commit e884c58310

View file

@ -5,7 +5,10 @@
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
import { HNSWIndex } from './hnsw/hnswIndex.js' import { HNSWIndex } from './hnsw/hnswIndex.js'
import { HNSWIndexOptimized, HNSWOptimizedConfig } from './hnsw/hnswIndexOptimized.js' import {
HNSWIndexOptimized,
HNSWOptimizedConfig
} from './hnsw/hnswIndexOptimized.js'
import { createStorage } from './storage/opfsStorage.js' import { createStorage } from './storage/opfsStorage.js'
import { import {
DistanceFunction, DistanceFunction,
@ -93,7 +96,6 @@ export interface BrainyDataConfig {
*/ */
embeddingFunction?: EmbeddingFunction embeddingFunction?: EmbeddingFunction
/** /**
* Set the database to read-only mode * Set the database to read-only mode
* When true, all write operations will throw an error * When true, all write operations will throw an error
@ -166,7 +168,8 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
config.embeddingFunction || defaultEmbeddingFunction config.embeddingFunction || defaultEmbeddingFunction
// Set persistent storage request flag // Set persistent storage request flag
this.requestPersistentStorage = config.storage?.requestPersistentStorage || false this.requestPersistentStorage =
config.storage?.requestPersistentStorage || false
// Set read-only flag // Set read-only flag
this.readOnly = config.readOnly || false this.readOnly = config.readOnly || false
@ -496,7 +499,9 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
// Process this batch in parallel // Process this batch in parallel
const batchResults = await Promise.all( const batchResults = await Promise.all(
batch.map(item => this.add(item.vectorOrData, item.metadata, options)) batch.map((item) =>
this.add(item.vectorOrData, item.metadata, options)
)
) )
// Add the results to our ids array // Add the results to our ids array
@ -687,10 +692,10 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
const verbResults = await this.searchVerbs(queryVectorOrData, k, { const verbResults = await this.searchVerbs(queryVectorOrData, k, {
forceEmbed: options.forceEmbed, forceEmbed: options.forceEmbed,
verbTypes: options.verbTypes verbTypes: options.verbTypes
}); })
// Convert verb results to SearchResult format // Convert verb results to SearchResult format
return verbResults.map(verb => ({ return verbResults.map((verb) => ({
id: verb.id, id: verb.id,
score: verb.similarity, score: verb.similarity,
vector: verb.embedding || [], vector: verb.embedding || [],
@ -700,7 +705,7 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
target: verb.target, target: verb.target,
...verb.data ...verb.data
} as unknown as T } as unknown as T
})); }))
} }
// If searching for nouns connected by verbs // If searching for nouns connected by verbs
@ -709,7 +714,7 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
forceEmbed: options.forceEmbed, forceEmbed: options.forceEmbed,
verbTypes: options.verbTypes, verbTypes: options.verbTypes,
direction: options.verbDirection direction: options.verbDirection
}); })
} }
// If a specific search mode is specified, use the appropriate search method // If a specific search mode is specified, use the appropriate search method
@ -829,7 +834,7 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
// Filter out the original entity and limit to the requested number // Filter out the original entity and limit to the requested number
return searchResults return searchResults
.filter(result => result.id !== id) .filter((result) => result.id !== id)
.slice(0, options.limit || 10) .slice(0, options.limit || 10)
} }
@ -1338,7 +1343,9 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
} }
// Filter out verbs without embeddings // Filter out verbs without embeddings
verbs = verbs.filter(verb => verb.embedding && verb.embedding.length > 0) verbs = verbs.filter(
(verb) => verb.embedding && verb.embedding.length > 0
)
// Calculate similarity for each verb // Calculate similarity for each verb
const results: Array<GraphVerb & { similarity: number }> = [] const results: Array<GraphVerb & { similarity: number }> = []
@ -1420,8 +1427,8 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
// Filter by verb types if specified // Filter by verb types if specified
if (options.verbTypes && options.verbTypes.length > 0) { if (options.verbTypes && options.verbTypes.length > 0) {
connectedVerbs = connectedVerbs.filter(verb => connectedVerbs = connectedVerbs.filter(
verb.verb && options.verbTypes!.includes(verb.verb) (verb) => verb.verb && options.verbTypes!.includes(verb.verb)
) )
} }
@ -1942,7 +1949,7 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
nounsRestored: number nounsRestored: number
verbsRestored: number verbsRestored: number
}> { }> {
return this.restore(data, options); return this.restore(data, options)
} }
/** /**