in server/aws-lsp-codewhisperer/src/shared/localProjectContextController.ts [106:169]
public async init({
vectorLib,
ignoreFilePatterns = [],
respectUserGitIgnores = true,
includeSymlinks = false,
maxFileSizeMB = this.DEFAULT_MAX_FILE_SIZE_MB,
maxIndexSizeMB = this.DEFAULT_MAX_INDEX_SIZE_MB,
indexCacheDirPath = path.join(homedir(), '.aws', 'amazonq', 'cache'),
enableGpuAcceleration = false,
indexWorkerThreads = 0,
enableIndexing = false,
}: LocalProjectContextInitializationOptions = {}): Promise<void> {
try {
// update states according to configuration
this.includeSymlinks = includeSymlinks
this.maxFileSizeMB = maxFileSizeMB
this.maxIndexSizeMB = maxIndexSizeMB
this.respectUserGitIgnores = respectUserGitIgnores
this.ignoreFilePatterns = ignoreFilePatterns
if (indexCacheDirPath?.length > 0 && path.parse(indexCacheDirPath)) {
this.indexCacheDirPath = indexCacheDirPath
}
if (enableGpuAcceleration) {
process.env.Q_ENABLE_GPU = 'true'
} else {
delete process.env.Q_ENABLE_GPU
}
if (indexWorkerThreads && indexWorkerThreads > 0 && indexWorkerThreads < 100) {
process.env.Q_WORKER_THREADS = indexWorkerThreads.toString()
} else {
delete process.env.Q_WORKER_THREADS
}
this.log.info(
`Vector library initializing with GPU acceleration: ${enableGpuAcceleration}, ` +
`index worker thread count: ${indexWorkerThreads}`
)
// build index if vecLib was initialized but indexing was not enabled before
if (this._vecLib) {
if (enableIndexing && !this._isIndexingEnabled) {
void this.buildIndex()
}
this._isIndexingEnabled = enableIndexing
return
}
// initialize vecLib and index if needed
const libraryPath = this.getVectorLibraryPath()
const vecLib = vectorLib ?? (await eval(`import("${libraryPath}")`))
if (vecLib) {
this._vecLib = await vecLib.start(LIBRARY_DIR, this.clientName, this.indexCacheDirPath)
if (enableIndexing) {
void this.buildIndex()
}
LocalProjectContextController.instance = this
this._isIndexingEnabled = enableIndexing
} else {
this.log.warn(`Vector library could not be imported from: ${libraryPath}`)
}
} catch (error) {
this.log.error('Vector library failed to initialize:' + error)
}
}