@pleaseai/context-please-core 0.2.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +113 -46
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/context.d.ts +37 -12
  4. package/dist/context.d.ts.map +1 -1
  5. package/dist/context.js +199 -73
  6. package/dist/context.js.map +1 -1
  7. package/dist/embedding/base-embedding.d.ts.map +1 -1
  8. package/dist/embedding/base-embedding.js +5 -1
  9. package/dist/embedding/base-embedding.js.map +1 -1
  10. package/dist/embedding/gemini-embedding.d.ts +43 -1
  11. package/dist/embedding/gemini-embedding.d.ts.map +1 -1
  12. package/dist/embedding/gemini-embedding.js +160 -31
  13. package/dist/embedding/gemini-embedding.js.map +1 -1
  14. package/dist/embedding/huggingface-embedding.d.ts +70 -0
  15. package/dist/embedding/huggingface-embedding.d.ts.map +1 -0
  16. package/dist/embedding/huggingface-embedding.js +270 -0
  17. package/dist/embedding/huggingface-embedding.js.map +1 -0
  18. package/dist/embedding/index.d.ts +3 -2
  19. package/dist/embedding/index.d.ts.map +1 -1
  20. package/dist/embedding/index.js +3 -2
  21. package/dist/embedding/index.js.map +1 -1
  22. package/dist/embedding/ollama-embedding.d.ts +2 -1
  23. package/dist/embedding/ollama-embedding.d.ts.map +1 -1
  24. package/dist/embedding/ollama-embedding.js +5 -5
  25. package/dist/embedding/ollama-embedding.js.map +1 -1
  26. package/dist/embedding/openai-embedding.d.ts +2 -1
  27. package/dist/embedding/openai-embedding.d.ts.map +1 -1
  28. package/dist/embedding/openai-embedding.js +10 -10
  29. package/dist/embedding/openai-embedding.js.map +1 -1
  30. package/dist/embedding/voyageai-embedding.d.ts +2 -1
  31. package/dist/embedding/voyageai-embedding.d.ts.map +1 -1
  32. package/dist/embedding/voyageai-embedding.js +23 -23
  33. package/dist/embedding/voyageai-embedding.js.map +1 -1
  34. package/dist/index.d.ts +4 -4
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +4 -4
  37. package/dist/index.js.map +1 -1
  38. package/dist/splitter/ast-splitter.d.ts +1 -1
  39. package/dist/splitter/ast-splitter.d.ts.map +1 -1
  40. package/dist/splitter/ast-splitter.js +29 -15
  41. package/dist/splitter/ast-splitter.js.map +1 -1
  42. package/dist/splitter/index.d.ts +4 -4
  43. package/dist/splitter/index.d.ts.map +1 -1
  44. package/dist/splitter/index.js +1 -1
  45. package/dist/splitter/index.js.map +1 -1
  46. package/dist/splitter/langchain-splitter.d.ts +1 -1
  47. package/dist/splitter/langchain-splitter.d.ts.map +1 -1
  48. package/dist/splitter/langchain-splitter.js.map +1 -1
  49. package/dist/sync/merkle.d.ts.map +1 -1
  50. package/dist/sync/merkle.js +9 -9
  51. package/dist/sync/merkle.js.map +1 -1
  52. package/dist/sync/synchronizer.d.ts.map +1 -1
  53. package/dist/sync/synchronizer.js +15 -15
  54. package/dist/sync/synchronizer.js.map +1 -1
  55. package/dist/types.d.ts.map +1 -1
  56. package/dist/utils/env-manager.d.ts.map +1 -1
  57. package/dist/utils/env-manager.js +3 -3
  58. package/dist/utils/env-manager.js.map +1 -1
  59. package/dist/utils/index.d.ts.map +1 -1
  60. package/dist/utils/index.js.map +1 -1
  61. package/dist/vectordb/base/base-vector-database.d.ts +1 -1
  62. package/dist/vectordb/base/base-vector-database.d.ts.map +1 -1
  63. package/dist/vectordb/base/base-vector-database.js.map +1 -1
  64. package/dist/vectordb/factory.d.ts +26 -7
  65. package/dist/vectordb/factory.d.ts.map +1 -1
  66. package/dist/vectordb/factory.js +68 -2
  67. package/dist/vectordb/factory.js.map +1 -1
  68. package/dist/vectordb/faiss-vectordb.d.ts +162 -0
  69. package/dist/vectordb/faiss-vectordb.d.ts.map +1 -0
  70. package/dist/vectordb/faiss-vectordb.js +762 -0
  71. package/dist/vectordb/faiss-vectordb.js.map +1 -0
  72. package/dist/vectordb/index.d.ts +10 -9
  73. package/dist/vectordb/index.d.ts.map +1 -1
  74. package/dist/vectordb/index.js +28 -9
  75. package/dist/vectordb/index.js.map +1 -1
  76. package/dist/vectordb/milvus-restful-vectordb.d.ts +6 -5
  77. package/dist/vectordb/milvus-restful-vectordb.d.ts.map +1 -1
  78. package/dist/vectordb/milvus-restful-vectordb.js +136 -136
  79. package/dist/vectordb/milvus-restful-vectordb.js.map +1 -1
  80. package/dist/vectordb/milvus-vectordb.d.ts +5 -4
  81. package/dist/vectordb/milvus-vectordb.d.ts.map +1 -1
  82. package/dist/vectordb/milvus-vectordb.js +31 -31
  83. package/dist/vectordb/milvus-vectordb.js.map +1 -1
  84. package/dist/vectordb/qdrant-vectordb.d.ts +28 -3
  85. package/dist/vectordb/qdrant-vectordb.d.ts.map +1 -1
  86. package/dist/vectordb/qdrant-vectordb.js +298 -73
  87. package/dist/vectordb/qdrant-vectordb.js.map +1 -1
  88. package/dist/vectordb/sparse/index.d.ts +2 -2
  89. package/dist/vectordb/sparse/index.d.ts.map +1 -1
  90. package/dist/vectordb/sparse/index.js +4 -4
  91. package/dist/vectordb/sparse/index.js.map +1 -1
  92. package/dist/vectordb/sparse/simple-bm25.d.ts +13 -2
  93. package/dist/vectordb/sparse/simple-bm25.d.ts.map +1 -1
  94. package/dist/vectordb/sparse/simple-bm25.js +80 -9
  95. package/dist/vectordb/sparse/simple-bm25.js.map +1 -1
  96. package/dist/vectordb/sparse/sparse-vector-generator.d.ts +7 -7
  97. package/dist/vectordb/sparse/sparse-vector-generator.d.ts.map +1 -1
  98. package/dist/vectordb/sparse/types.d.ts.map +1 -1
  99. package/dist/vectordb/types.d.ts +12 -12
  100. package/dist/vectordb/types.d.ts.map +1 -1
  101. package/dist/vectordb/types.js +1 -1
  102. package/dist/vectordb/types.js.map +1 -1
  103. package/dist/vectordb/zilliz-utils.d.ts +10 -10
  104. package/dist/vectordb/zilliz-utils.d.ts.map +1 -1
  105. package/dist/vectordb/zilliz-utils.js +16 -17
  106. package/dist/vectordb/zilliz-utils.js.map +1 -1
  107. package/package.json +16 -13
package/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # @pleaseai/context-please-core
2
+
2
3
  ![](../../assets/claude-context.png)
3
4
 
4
5
  The core indexing engine for Context Please - a powerful tool for semantic search and analysis of codebases using vector embeddings and AI.
@@ -17,20 +18,24 @@ npm install @pleaseai/context-please-core
17
18
  ```
18
19
 
19
20
  ### Prepare Environment Variables
21
+
20
22
  #### OpenAI API key
23
+
21
24
  See [OpenAI Documentation](https://platform.openai.com/docs/api-reference) for more details to get your API key.
25
+
22
26
  ```bash
23
27
  OPENAI_API_KEY=your-openai-api-key
24
28
  ```
25
29
 
26
30
  #### Zilliz Cloud configuration
27
- Get a free Milvus vector database on Zilliz Cloud.
31
+
32
+ Get a free Milvus vector database on Zilliz Cloud.
28
33
 
29
34
  Claude Context needs a vector database. You can [sign up](https://cloud.zilliz.com/signup?utm_source=github&utm_medium=referral&utm_campaign=2507-codecontext-readme) on Zilliz Cloud to get a free Serverless cluster.
30
35
 
31
36
  ![](../../assets/signup_and_create_cluster.jpeg)
32
37
 
33
- After creating your cluster, open your Zilliz Cloud console and copy both the **public endpoint** and your **API key**.
38
+ After creating your cluster, open your Zilliz Cloud console and copy both the **public endpoint** and your **API key**.
34
39
  These will be used as `your-zilliz-cloud-public-endpoint` and `your-zilliz-cloud-api-key` in the configuration examples.
35
40
 
36
41
  ![Zilliz Cloud Dashboard](../../assets/zilliz_cloud_dashboard.jpeg)
@@ -42,56 +47,56 @@ If you need help creating your free vector database or finding these values, see
42
47
  ```bash
43
48
  MILVUS_ADDRESS=your-zilliz-cloud-public-endpoint
44
49
  MILVUS_TOKEN=your-zilliz-cloud-api-key
45
- ```
50
+ ```
46
51
 
47
52
  > 💡 **Tip**: For easier configuration management across different usage scenarios, consider using [global environment variables](../../docs/getting-started/environment-variables.md).
48
53
 
49
54
  ## Quick Start
50
55
 
51
56
  ```typescript
52
- import {
53
- Context,
54
- OpenAIEmbedding,
55
- MilvusVectorDatabase
56
- } from '@pleaseai/context-please-core';
57
+ import {
58
+ Context,
59
+ MilvusVectorDatabase,
60
+ OpenAIEmbedding
61
+ } from '@pleaseai/context-please-core'
57
62
 
58
63
  // Initialize embedding provider
59
64
  const embedding = new OpenAIEmbedding({
60
65
  apiKey: process.env.OPENAI_API_KEY || 'your-openai-api-key',
61
66
  model: 'text-embedding-3-small'
62
- });
67
+ })
63
68
 
64
69
  // Initialize vector database
65
70
  const vectorDatabase = new MilvusVectorDatabase({
66
71
  address: process.env.MILVUS_ADDRESS || 'localhost:19530',
67
72
  token: process.env.MILVUS_TOKEN || ''
68
- });
73
+ })
69
74
 
70
75
  // Create context instance
71
76
  const context = new Context({
72
77
  embedding,
73
78
  vectorDatabase
74
- });
79
+ })
75
80
 
76
81
  // Index a codebase
77
82
  const stats = await context.indexCodebase('./my-project', (progress) => {
78
- console.log(`${progress.phase} - ${progress.percentage}%`);
79
- });
83
+ console.log(`${progress.phase} - ${progress.percentage}%`)
84
+ })
80
85
 
81
- console.log(`Indexed ${stats.indexedFiles} files with ${stats.totalChunks} chunks`);
86
+ console.log(`Indexed ${stats.indexedFiles} files with ${stats.totalChunks} chunks`)
82
87
 
83
88
  // Search the codebase
84
89
  const results = await context.semanticSearch(
85
90
  './my-project',
86
91
  'function that handles user authentication',
87
92
  5
88
- );
93
+ )
89
94
 
90
- results.forEach(result => {
91
- console.log(`${result.relativePath}:${result.startLine}-${result.endLine}`);
92
- console.log(`Score: ${result.score}`);
93
- console.log(result.content);
94
- });
95
+ results.forEach((result) => {
96
+ console.log(`${result.relativePath}:${result.startLine}-${result.endLine}`)
97
+ console.log(`Score: ${result.score}`)
98
+ console.log(result.content)
99
+ })
95
100
  ```
96
101
 
97
102
  ## Features
@@ -126,13 +131,13 @@ results.forEach(result => {
126
131
 
127
132
  ```typescript
128
133
  interface ContextConfig {
129
- embedding?: Embedding; // Embedding provider
130
- vectorDatabase?: VectorDatabase; // Vector database instance (required)
131
- codeSplitter?: Splitter; // Code splitting strategy
132
- supportedExtensions?: string[]; // File extensions to index
133
- ignorePatterns?: string[]; // Patterns to ignore
134
- customExtensions?: string[]; // Custom extensions from MCP
135
- customIgnorePatterns?: string[]; // Custom ignore patterns from MCP
134
+ embedding?: Embedding // Embedding provider
135
+ vectorDatabase?: VectorDatabase // Vector database instance (required)
136
+ codeSplitter?: Splitter // Code splitting strategy
137
+ supportedExtensions?: string[] // File extensions to index
138
+ ignorePatterns?: string[] // Patterns to ignore
139
+ customExtensions?: string[] // Custom extensions from MCP
140
+ customIgnorePatterns?: string[] // Custom ignore patterns from MCP
136
141
  }
137
142
  ```
138
143
 
@@ -141,10 +146,30 @@ interface ContextConfig {
141
146
  ```typescript
142
147
  [
143
148
  // Programming languages
144
- '.ts', '.tsx', '.js', '.jsx', '.py', '.java', '.cpp', '.c', '.h', '.hpp',
145
- '.cs', '.go', '.rs', '.php', '.rb', '.swift', '.kt', '.scala', '.m', '.mm',
146
- // Text and markup files
147
- '.md', '.markdown', '.ipynb'
149
+ '.ts',
150
+ '.tsx',
151
+ '.js',
152
+ '.jsx',
153
+ '.py',
154
+ '.java',
155
+ '.cpp',
156
+ '.c',
157
+ '.h',
158
+ '.hpp',
159
+ '.cs',
160
+ '.go',
161
+ '.rs',
162
+ '.php',
163
+ '.rb',
164
+ '.swift',
165
+ '.kt',
166
+ '.scala',
167
+ '.m',
168
+ '.mm',
169
+ // Text and markup files
170
+ '.md',
171
+ '.markdown',
172
+ '.ipynb'
148
173
  ]
149
174
  ```
150
175
 
@@ -180,38 +205,76 @@ interface ContextConfig {
180
205
 
181
206
  ```typescript
182
207
  interface SemanticSearchResult {
183
- content: string; // Code content
184
- relativePath: string; // File path relative to codebase root
185
- startLine: number; // Starting line number
186
- endLine: number; // Ending line number
187
- language: string; // Programming language
188
- score: number; // Similarity score (0-1)
208
+ content: string // Code content
209
+ relativePath: string // File path relative to codebase root
210
+ startLine: number // Starting line number
211
+ endLine: number // Ending line number
212
+ language: string // Programming language
213
+ score: number // Similarity score (0-1)
189
214
  }
190
215
  ```
191
216
 
192
-
193
217
  ## Examples
194
218
 
195
219
  ### Using VoyageAI Embeddings
196
220
 
197
221
  ```typescript
198
- import { Context, MilvusVectorDatabase, VoyageAIEmbedding } from '@pleaseai/context-please-core';
222
+ import { Context, MilvusVectorDatabase, VoyageAIEmbedding } from '@pleaseai/context-please-core'
199
223
 
200
224
  // Initialize with VoyageAI embedding provider
201
225
  const embedding = new VoyageAIEmbedding({
202
226
  apiKey: process.env.VOYAGEAI_API_KEY || 'your-voyageai-api-key',
203
227
  model: 'voyage-code-3'
204
- });
228
+ })
205
229
 
206
230
  const vectorDatabase = new MilvusVectorDatabase({
207
231
  address: process.env.MILVUS_ADDRESS || 'localhost:19530',
208
232
  token: process.env.MILVUS_TOKEN || ''
209
- });
233
+ })
210
234
 
211
235
  const context = new Context({
212
236
  embedding,
213
237
  vectorDatabase
214
- });
238
+ })
239
+ ```
240
+
241
+ ### Using Gemini Embeddings with Retry Configuration
242
+
243
+ ```typescript
244
+ import { Context, MilvusVectorDatabase, GeminiEmbedding } from '@pleaseai/context-please-core'
245
+
246
+ // Initialize with Gemini embedding provider
247
+ const embedding = new GeminiEmbedding({
248
+ apiKey: process.env.GEMINI_API_KEY || 'your-gemini-api-key',
249
+ model: 'gemini-embedding-001',
250
+ outputDimensionality: 768, // Optional: Matryoshka Representation Learning support (256, 768, 1536, 3072)
251
+ maxRetries: 3, // Optional: Maximum retry attempts (default: 3)
252
+ baseDelay: 1000 // Optional: Base delay in ms for exponential backoff (default: 1000ms)
253
+ })
254
+
255
+ const vectorDatabase = new MilvusVectorDatabase({
256
+ address: process.env.MILVUS_ADDRESS || 'localhost:19530',
257
+ token: process.env.MILVUS_TOKEN || ''
258
+ })
259
+
260
+ const context = new Context({
261
+ embedding,
262
+ vectorDatabase
263
+ })
264
+
265
+ // The retry mechanism automatically handles:
266
+ // - Rate limit errors (429)
267
+ // - Server errors (500, 502, 503, 504)
268
+ // - Network errors (ECONNREFUSED, ETIMEDOUT, ENOTFOUND, EAI_AGAIN)
269
+ // - Transient API failures with exponential backoff (1s → 2s → 4s → 8s, capped at 10s)
270
+
271
+ // Update retry configuration at runtime
272
+ embedding.setMaxRetries(5)
273
+ embedding.setBaseDelay(2000)
274
+
275
+ // Check current retry configuration
276
+ const retryConfig = embedding.getRetryConfig()
277
+ console.log(`Max retries: ${retryConfig.maxRetries}, Base delay: ${retryConfig.baseDelay}ms`)
215
278
  ```
216
279
 
217
280
  ### Custom File Filtering
@@ -227,7 +290,7 @@ const context = new Context({
227
290
  '*.spec.ts',
228
291
  '*.test.js'
229
292
  ]
230
- });
293
+ })
231
294
  ```
232
295
 
233
296
  ## File Synchronization Architecture
@@ -241,21 +304,25 @@ Claude Context implements an intelligent file synchronization system that effici
241
304
  The file synchronization system uses a **Merkle tree-based approach** combined with SHA-256 file hashing to detect changes:
242
305
 
243
306
  #### 1. File Hashing
307
+
244
308
  - Each file in the codebase is hashed using SHA-256
245
309
  - File hashes are computed based on file content, not metadata
246
310
  - Hashes are stored with relative file paths for consistency across different environments
247
311
 
248
312
  #### 2. Merkle Tree Construction
313
+
249
314
  - All file hashes are organized into a Merkle tree structure
250
315
  - The tree provides a single root hash that represents the entire codebase state
251
316
  - Any change to any file will cause the root hash to change
252
317
 
253
318
  #### 3. Snapshot Management
319
+
254
320
  - File synchronization state is persisted to `~/.context/merkle/` directory
255
321
  - Each codebase gets a unique snapshot file based on its absolute path hash
256
322
  - Snapshots contain both file hashes and serialized Merkle tree data
257
323
 
258
324
  #### 4. Change Detection Process
325
+
259
326
  1. **Quick Check**: Compare current Merkle root hash with stored snapshot
260
327
  2. **Detailed Analysis**: If root hashes differ, perform file-by-file comparison
261
328
  3. **Change Classification**: Categorize changes into three types:
@@ -264,15 +331,16 @@ The file synchronization system uses a **Merkle tree-based approach** combined w
264
331
  - **Removed**: Files that were deleted from the codebase
265
332
 
266
333
  #### 5. Incremental Updates
334
+
267
335
  - Only process files that have actually changed
268
336
  - Update vector database entries only for modified chunks
269
337
  - Remove entries for deleted files
270
338
  - Add entries for new files
271
339
 
272
-
273
340
  ## Contributing
274
341
 
275
342
  This package is part of the Claude Context monorepo. Please see:
343
+
276
344
  - [Main Contributing Guide](../../CONTRIBUTING.md) - General contribution guidelines
277
345
  - [Core Package Contributing](CONTRIBUTING.md) - Specific development guide for this package
278
346
 
@@ -281,7 +349,6 @@ This package is part of the Claude Context monorepo. Please see:
281
349
  - **[@claude-context/mcp](../mcp)** - MCP server that uses this core engine
282
350
  - **[VSCode Extension](../vscode-extension)** - VSCode extension built on this core
283
351
 
284
-
285
352
  ## License
286
353
 
287
- MIT - See [LICENSE](../../LICENSE) for details
354
+ MIT - See [LICENSE](../../LICENSE) for details