Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/types/src/codebase-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export const codebaseIndexConfigSchema = z.object({
// OpenAI Compatible specific fields
codebaseIndexOpenAiCompatibleBaseUrl: z.string().optional(),
codebaseIndexOpenAiCompatibleModelDimension: z.number().optional(),
// Memory optimization settings
codebaseIndexUseOnDiskStorage: z.boolean().optional(),
codebaseIndexMemoryMapThreshold: z.number().optional(),
codebaseIndexHnswEfSearch: z.number().optional(),
})

export type CodebaseIndexConfig = z.infer<typeof codebaseIndexConfigSchema>
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export * from "./tool.js"
export * from "./type-fu.js"
export * from "./vscode.js"
export * from "./todo.js"
export * from "./qdrant.js"
141 changes: 141 additions & 0 deletions packages/types/src/qdrant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/**
* Qdrant Vector Store Configuration Constants
*
* These constants define default values for Qdrant memory optimization settings
* to reduce RAM usage by storing vectors and indexes on disk instead of in memory.
*/

/**
* Default memory optimization settings for Qdrant
*/
export const QDRANT_MEMORY_OPTIMIZATION_DEFAULTS = {
/**
* Enable on-disk storage for vectors and HNSW indexes by default
* This significantly reduces memory usage at the cost of slightly slower access
*/
USE_ON_DISK_STORAGE: true,

/**
* Number of vectors before using memory-mapped files
* Segments larger than this threshold will use memory-mapped files for better memory management
*/
MEMORY_MAP_THRESHOLD: 50000,

/**
* HNSW search parameter (ef) - controls search quality vs memory usage
* Higher values = better search quality but more memory usage
* Lower values = less memory usage but potentially lower search quality
* Default: 128 (original value, not reduced for testing purposes)
*/
HNSW_EF_SEARCH: 128,
} as const

/**
* HNSW (Hierarchical Navigable Small World) index configuration constants
*/
export const QDRANT_HNSW_CONFIG_DEFAULTS = {
/**
* Number of bi-directional links created for each node during construction
*/
M: 16,

/**
* Size of the dynamic list during index construction
*/
EF_CONSTRUCT: 100,

/**
* Use full scan for collections smaller than this threshold
*/
FULL_SCAN_THRESHOLD: 10000,

/**
* Maximum number of threads for indexing (0 = use all available CPU cores)
*/
MAX_INDEXING_THREADS: 0,

/**
* Payload index configuration (null = use default)
*/
PAYLOAD_M: null,
} as const

/**
* Optimizer configuration constants for memory-mapped storage
*/
export const QDRANT_OPTIMIZER_CONFIG_DEFAULTS = {
/**
* Trigger optimization when this percentage of vectors are deleted
*/
DELETED_THRESHOLD: 0.2,

/**
* Minimum number of vectors before vacuum operation
*/
VACUUM_MIN_VECTOR_NUMBER: 1000,

/**
* Default number of segments to create
*/
DEFAULT_SEGMENT_NUMBER: 2,

/**
* Maximum segment size (null = no limit)
*/
MAX_SEGMENT_SIZE: null,

/**
* Start indexing after this many vectors
*/
INDEXING_THRESHOLD: 20000,

/**
* Flush to disk interval in seconds
*/
FLUSH_INTERVAL_SEC: 5,

/**
* Maximum optimization threads (0 = use all available CPU cores)
*/
MAX_OPTIMIZATION_THREADS: 0,
} as const

/**
* Quantization configuration for additional memory efficiency
*/
export const QDRANT_QUANTIZATION_CONFIG_DEFAULTS = {
/**
* Enable quantization for memory efficiency
*/
IGNORE: false,

/**
* Rescore with original vectors for accuracy
*/
RESCORE: true,

/**
* Oversample to maintain quality
*/
OVERSAMPLING: 2.0,
} as const

/**
* Memory optimization configuration interface
*/
export interface QdrantMemoryOptimizationConfig {
/**
* Enable on-disk storage for vectors and indexes
*/
useOnDiskStorage?: boolean

/**
* Number of vectors before using memory-mapped files
*/
memoryMapThreshold?: number

/**
* HNSW search parameter (ef) - controls search quality vs memory usage
*/
hnswEfSearch?: number
}
40 changes: 40 additions & 0 deletions src/services/code-index/__tests__/config-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,18 @@ describe("CodeIndexConfigManager", () => {
isConfigured: false,
embedderProvider: "openai",
modelId: undefined,
modelDimension: undefined,
openAiOptions: { openAiNativeApiKey: "" },
ollamaOptions: { ollamaBaseUrl: "" },
openAiCompatibleOptions: undefined,
geminiOptions: undefined,
mistralOptions: undefined,
qdrantUrl: "http://localhost:6333",
qdrantApiKey: "",
searchMinScore: 0.4,
useOnDiskStorage: true,
memoryMapThreshold: 50000,
hnswEfSearch: 128,
})
expect(result.requiresRestart).toBe(false)
})
Expand All @@ -135,11 +142,18 @@ describe("CodeIndexConfigManager", () => {
isConfigured: true,
embedderProvider: "openai",
modelId: "text-embedding-3-large",
modelDimension: undefined,
openAiOptions: { openAiNativeApiKey: "test-openai-key" },
ollamaOptions: { ollamaBaseUrl: "" },
openAiCompatibleOptions: undefined,
geminiOptions: undefined,
mistralOptions: undefined,
qdrantUrl: "http://qdrant.local",
qdrantApiKey: "test-qdrant-key",
searchMinScore: 0.4,
useOnDiskStorage: true,
memoryMapThreshold: 50000,
hnswEfSearch: 128,
})
})

Expand Down Expand Up @@ -168,15 +182,21 @@ describe("CodeIndexConfigManager", () => {
isConfigured: true,
embedderProvider: "openai-compatible",
modelId: "text-embedding-3-large",
modelDimension: undefined,
openAiOptions: { openAiNativeApiKey: "" },
ollamaOptions: { ollamaBaseUrl: "" },
openAiCompatibleOptions: {
baseUrl: "https://api.example.com/v1",
apiKey: "test-openai-compatible-key",
},
geminiOptions: undefined,
mistralOptions: undefined,
qdrantUrl: "http://qdrant.local",
qdrantApiKey: "test-qdrant-key",
searchMinScore: 0.4,
useOnDiskStorage: true,
memoryMapThreshold: 50000,
hnswEfSearch: 128,
})
})

Expand Down Expand Up @@ -212,9 +232,14 @@ describe("CodeIndexConfigManager", () => {
baseUrl: "https://api.example.com/v1",
apiKey: "test-openai-compatible-key",
},
geminiOptions: undefined,
mistralOptions: undefined,
qdrantUrl: "http://qdrant.local",
qdrantApiKey: "test-qdrant-key",
searchMinScore: 0.4,
useOnDiskStorage: true,
memoryMapThreshold: 50000,
hnswEfSearch: 128,
})
})

Expand Down Expand Up @@ -243,16 +268,22 @@ describe("CodeIndexConfigManager", () => {
isConfigured: true,
embedderProvider: "openai-compatible",
modelId: "custom-model",
modelDimension: undefined,
openAiOptions: { openAiNativeApiKey: "" },
ollamaOptions: { ollamaBaseUrl: "" },
openAiCompatibleOptions: {
baseUrl: "https://api.example.com/v1",
apiKey: "test-openai-compatible-key",
// modelDimension is undefined when not set
},
geminiOptions: undefined,
mistralOptions: undefined,
qdrantUrl: "http://qdrant.local",
qdrantApiKey: "test-qdrant-key",
searchMinScore: 0.4,
useOnDiskStorage: true,
memoryMapThreshold: 50000,
hnswEfSearch: 128,
})
})

Expand Down Expand Up @@ -289,9 +320,13 @@ describe("CodeIndexConfigManager", () => {
apiKey: "test-openai-compatible-key",
},
geminiOptions: undefined,
mistralOptions: undefined,
qdrantUrl: "http://qdrant.local",
qdrantApiKey: "test-qdrant-key",
searchMinScore: 0.4,
useOnDiskStorage: true,
memoryMapThreshold: 50000,
hnswEfSearch: 128,
})
})

Expand Down Expand Up @@ -1292,14 +1327,19 @@ describe("CodeIndexConfigManager", () => {
isConfigured: true,
embedderProvider: "openai",
modelId: "text-embedding-3-large",
modelDimension: undefined,
openAiOptions: { openAiNativeApiKey: "test-openai-key" },
ollamaOptions: { ollamaBaseUrl: undefined },
geminiOptions: undefined,
openAiCompatibleOptions: undefined,
mistralOptions: undefined,
qdrantUrl: "http://qdrant.local",
qdrantApiKey: "test-qdrant-key",
searchMinScore: 0.4,
searchMaxResults: 50,
useOnDiskStorage: true,
memoryMapThreshold: 50000,
hnswEfSearch: 128,
})
})

Expand Down
Loading
Loading