@zokizuan/satori-core 1.3.0 → 1.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.
@@ -383,7 +383,7 @@ class Context {
383
383
  if (isHybrid === true) {
384
384
  try {
385
385
  // Check collection stats to see if it has data
386
- const stats = await this.vectorDatabase.query(collectionName, '', ['id'], 1);
386
+ await this.vectorDatabase.query(collectionName, '', ['id'], 1);
387
387
  console.log(`[Context] 🔍 Collection '${collectionName}' exists and appears to have data`);
388
388
  }
389
389
  catch (error) {
@@ -631,7 +631,7 @@ class Context {
631
631
  const collectionExists = await this.vectorDatabase.hasCollection(collectionName);
632
632
  progressCallback?.({ phase: 'Removing index data...', current: 50, total: 100, percentage: 50 });
633
633
  if (collectionExists) {
634
- await this.vectorDatabase.dropCollection(collectionName);
634
+ await (0, vectordb_1.deleteCollectionWithVerification)(this.vectorDatabase, collectionName);
635
635
  }
636
636
  // Delete snapshot file
637
637
  await synchronizer_1.FileSynchronizer.deleteSnapshot(codebasePath);
@@ -991,7 +991,10 @@ class Context {
991
991
  }
992
992
  const relativePath = path.relative(codebasePath, chunk.metadata.filePath);
993
993
  const fileExtension = path.extname(chunk.metadata.filePath);
994
- const { filePath, startLine, endLine, ...restMetadata } = chunk.metadata;
994
+ const { filePath: omittedFilePath, startLine: omittedStartLine, endLine: omittedEndLine, ...restMetadata } = chunk.metadata;
995
+ void omittedFilePath;
996
+ void omittedStartLine;
997
+ void omittedEndLine;
995
998
  return {
996
999
  id: this.generateId(relativePath, chunk.metadata.startLine || 0, chunk.metadata.endLine || 0, chunk.content),
997
1000
  content: chunk.content, // Full text content for BM25 and storage
@@ -1020,7 +1023,10 @@ class Context {
1020
1023
  }
1021
1024
  const relativePath = path.relative(codebasePath, chunk.metadata.filePath);
1022
1025
  const fileExtension = path.extname(chunk.metadata.filePath);
1023
- const { filePath, startLine, endLine, ...restMetadata } = chunk.metadata;
1026
+ const { filePath: omittedFilePath, startLine: omittedStartLine, endLine: omittedEndLine, ...restMetadata } = chunk.metadata;
1027
+ void omittedFilePath;
1028
+ void omittedStartLine;
1029
+ void omittedEndLine;
1024
1030
  return {
1025
1031
  id: this.generateId(relativePath, chunk.metadata.startLine || 0, chunk.metadata.endLine || 0, chunk.content),
1026
1032
  vector: embeddings[index].vector,
@@ -1157,7 +1163,7 @@ class Context {
1157
1163
  return [];
1158
1164
  }
1159
1165
  }
1160
- catch (error) {
1166
+ catch {
1161
1167
  if (fileName.includes('global')) {
1162
1168
  console.log(`📄 No ${fileName} file found`);
1163
1169
  }
@@ -156,7 +156,7 @@ class AstCodeSplitter {
156
156
  }
157
157
  return this.addOverlap(refinedChunks);
158
158
  }
159
- splitLargeChunk(chunk, originalCode) {
159
+ splitLargeChunk(chunk, _originalCode) {
160
160
  const lines = chunk.content.split('\n');
161
161
  const subChunks = [];
162
162
  let currentChunk = '';
@@ -23,7 +23,7 @@ class LangChainCodeSplitter {
23
23
  // Split code
24
24
  const documents = await splitter.createDocuments([code]);
25
25
  // Convert to CodeChunk format
26
- return documents.map((doc, index) => {
26
+ return documents.map((doc) => {
27
27
  const lines = doc.metadata?.loc?.lines || { from: 1, to: 1 };
28
28
  return {
29
29
  content: doc.pageContent,
@@ -86,7 +86,7 @@ class LangChainCodeSplitter {
86
86
  chunkOverlap: this.chunkOverlap,
87
87
  });
88
88
  const documents = await splitter.createDocuments([code]);
89
- return documents.map((doc, index) => {
89
+ return documents.map((doc) => {
90
90
  const lines = this.estimateLines(doc.pageContent, code);
91
91
  return {
92
92
  content: doc.pageContent,
@@ -101,7 +101,6 @@ class LangChainCodeSplitter {
101
101
  }
102
102
  estimateLines(chunk, originalCode) {
103
103
  // Simple line number estimation
104
- const codeLines = originalCode.split('\n');
105
104
  const chunkLines = chunk.split('\n');
106
105
  // Find chunk position in original code
107
106
  const chunkStart = originalCode.indexOf(chunk);
@@ -64,7 +64,7 @@ class EnvManager {
64
64
  }
65
65
  }
66
66
  }
67
- catch (error) {
67
+ catch {
68
68
  // Ignore file read errors
69
69
  }
70
70
  return undefined;
@@ -1,5 +1,6 @@
1
1
  export { VectorDocument, SearchOptions, VectorSearchResult, VectorDatabase, CollectionDetails, VectorStoreBackendInfo, HybridSearchRequest, HybridSearchOptions, HybridSearchResult, RerankStrategy, RetrievalMode, ScorePolicy, BackendScoreKind, IndexCompletionFingerprint, IndexCompletionMarkerDocument, INDEX_COMPLETION_MARKER_DOC_ID, INDEX_COMPLETION_MARKER_FILE_EXTENSION, INDEX_COMPLETION_MARKER_RELATIVE_PATH, COLLECTION_LIMIT_MESSAGE } from './types';
2
2
  export { MilvusRestfulVectorDatabase, MilvusRestfulConfig } from './milvus-restful-vectordb';
3
3
  export { MilvusVectorDatabase, MilvusConfig } from './milvus-vectordb';
4
+ export { RemoteCollectionDeletePendingError, deleteCollectionWithVerification, VerifiedCollectionDeleteOptions, VerifiedCollectionDeleteResult } from './remote-delete';
4
5
  export { ClusterManager, ZillizConfig, Project, Cluster, CreateFreeClusterRequest, CreateFreeClusterResponse, CreateFreeClusterWithDetailsResponse, DescribeClusterResponse } from './zilliz-utils';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClusterManager = exports.MilvusVectorDatabase = exports.MilvusRestfulVectorDatabase = exports.COLLECTION_LIMIT_MESSAGE = exports.INDEX_COMPLETION_MARKER_RELATIVE_PATH = exports.INDEX_COMPLETION_MARKER_FILE_EXTENSION = exports.INDEX_COMPLETION_MARKER_DOC_ID = void 0;
3
+ exports.ClusterManager = exports.deleteCollectionWithVerification = exports.RemoteCollectionDeletePendingError = exports.MilvusVectorDatabase = exports.MilvusRestfulVectorDatabase = exports.COLLECTION_LIMIT_MESSAGE = exports.INDEX_COMPLETION_MARKER_RELATIVE_PATH = exports.INDEX_COMPLETION_MARKER_FILE_EXTENSION = exports.INDEX_COMPLETION_MARKER_DOC_ID = void 0;
4
4
  // Re-export types and interfaces
5
5
  var types_1 = require("./types");
6
6
  Object.defineProperty(exports, "INDEX_COMPLETION_MARKER_DOC_ID", { enumerable: true, get: function () { return types_1.INDEX_COMPLETION_MARKER_DOC_ID; } });
@@ -12,6 +12,9 @@ var milvus_restful_vectordb_1 = require("./milvus-restful-vectordb");
12
12
  Object.defineProperty(exports, "MilvusRestfulVectorDatabase", { enumerable: true, get: function () { return milvus_restful_vectordb_1.MilvusRestfulVectorDatabase; } });
13
13
  var milvus_vectordb_1 = require("./milvus-vectordb");
14
14
  Object.defineProperty(exports, "MilvusVectorDatabase", { enumerable: true, get: function () { return milvus_vectordb_1.MilvusVectorDatabase; } });
15
+ var remote_delete_1 = require("./remote-delete");
16
+ Object.defineProperty(exports, "RemoteCollectionDeletePendingError", { enumerable: true, get: function () { return remote_delete_1.RemoteCollectionDeletePendingError; } });
17
+ Object.defineProperty(exports, "deleteCollectionWithVerification", { enumerable: true, get: function () { return remote_delete_1.deleteCollectionWithVerification; } });
15
18
  var zilliz_utils_1 = require("./zilliz-utils");
16
19
  Object.defineProperty(exports, "ClusterManager", { enumerable: true, get: function () { return zilliz_utils_1.ClusterManager; } });
17
20
  //# sourceMappingURL=index.js.map
@@ -47,7 +47,7 @@ export declare class MilvusRestfulVectorDatabase implements VectorDatabase {
47
47
  * Make HTTP request to Milvus REST API
48
48
  */
49
49
  private makeRequest;
50
- createCollection(collectionName: string, dimension: number, description?: string): Promise<void>;
50
+ createCollection(collectionName: string, dimension: number, _description?: string): Promise<void>;
51
51
  /**
52
52
  * Create index for vector field using the Index Create API
53
53
  */
@@ -65,7 +65,7 @@ export declare class MilvusRestfulVectorDatabase implements VectorDatabase {
65
65
  search(collectionName: string, queryVector: number[], options?: SearchOptions): Promise<VectorSearchResult[]>;
66
66
  delete(collectionName: string, ids: string[]): Promise<void>;
67
67
  query(collectionName: string, filter: string, outputFields: string[], limit?: number): Promise<Record<string, any>[]>;
68
- createHybridCollection(collectionName: string, dimension: number, description?: string): Promise<void>;
68
+ createHybridCollection(collectionName: string, dimension: number, _description?: string): Promise<void>;
69
69
  private createHybridIndexes;
70
70
  insertHybrid(collectionName: string, documents: VectorDocument[]): Promise<void>;
71
71
  hybridSearch(collectionName: string, searchRequests: HybridSearchRequest[], options?: HybridSearchOptions): Promise<HybridSearchResult[]>;
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.MilvusRestfulVectorDatabase = void 0;
14
14
  const types_1 = require("./types");
15
15
  const zilliz_utils_1 = require("./zilliz-utils");
16
+ const remote_delete_1 = require("./remote-delete");
16
17
  function normalizeHost(address) {
17
18
  const withProtocol = address.includes('://') ? address : `http://${address}`;
18
19
  try {
@@ -161,7 +162,7 @@ class MilvusRestfulVectorDatabase {
161
162
  throw error;
162
163
  }
163
164
  }
164
- async createCollection(collectionName, dimension, description) {
165
+ async createCollection(collectionName, dimension, _description) {
165
166
  await this.ensureInitialized();
166
167
  try {
167
168
  const restfulConfig = this.config;
@@ -495,7 +496,7 @@ class MilvusRestfulVectorDatabase {
495
496
  throw error;
496
497
  }
497
498
  }
498
- async createHybridCollection(collectionName, dimension, description) {
499
+ async createHybridCollection(collectionName, dimension, _description) {
499
500
  try {
500
501
  const restfulConfig = this.config;
501
502
  const collectionSchema = {
@@ -772,7 +773,7 @@ class MilvusRestfulVectorDatabase {
772
773
  };
773
774
  try {
774
775
  await createCollectionWithLimitCheck(this.makeRequest.bind(this), collectionSchema);
775
- await this.dropCollection(collectionName);
776
+ await (0, remote_delete_1.deleteCollectionWithVerification)(this, collectionName);
776
777
  return true;
777
778
  }
778
779
  catch (error) {
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MilvusVectorDatabase = void 0;
4
4
  const milvus2_sdk_node_1 = require("@zilliz/milvus2-sdk-node");
5
5
  const zilliz_utils_1 = require("./zilliz-utils");
6
+ const remote_delete_1 = require("./remote-delete");
6
7
  const COLLECTION_LIMIT_PATTERNS = [
7
8
  /exceeded the limit number of collections/i,
8
9
  /collection limit/i,
@@ -753,12 +754,7 @@ class MilvusVectorDatabase {
753
754
  };
754
755
  try {
755
756
  await this.client.createCollection(createCollectionParams);
756
- // Immediately drop the collection after successful creation
757
- if (await this.client.hasCollection({ collection_name: collectionName })) {
758
- await this.client.dropCollection({
759
- collection_name: collectionName,
760
- });
761
- }
757
+ await (0, remote_delete_1.deleteCollectionWithVerification)(this, collectionName);
762
758
  return true;
763
759
  }
764
760
  catch (error) {
@@ -0,0 +1,20 @@
1
+ import type { VectorDatabase } from './types';
2
+ export interface VerifiedCollectionDeleteOptions {
3
+ maxAttempts?: number;
4
+ initialBackoffMs?: number;
5
+ backoffMultiplier?: number;
6
+ sleep?: (ms: number) => Promise<void>;
7
+ }
8
+ export interface VerifiedCollectionDeleteResult {
9
+ collectionName: string;
10
+ attempts: number;
11
+ verifiedAbsent: boolean;
12
+ }
13
+ export declare class RemoteCollectionDeletePendingError extends Error {
14
+ readonly collectionName: string;
15
+ readonly attempts: number;
16
+ readonly lastError?: unknown;
17
+ constructor(collectionName: string, attempts: number, lastError?: unknown);
18
+ }
19
+ export declare function deleteCollectionWithVerification(vectorDatabase: Pick<VectorDatabase, 'dropCollection' | 'hasCollection'>, collectionName: string, options?: VerifiedCollectionDeleteOptions): Promise<VerifiedCollectionDeleteResult>;
20
+ //# sourceMappingURL=remote-delete.d.ts.map
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RemoteCollectionDeletePendingError = void 0;
4
+ exports.deleteCollectionWithVerification = deleteCollectionWithVerification;
5
+ const DEFAULT_MAX_ATTEMPTS = 5;
6
+ const DEFAULT_INITIAL_BACKOFF_MS = 100;
7
+ const DEFAULT_BACKOFF_MULTIPLIER = 2;
8
+ function defaultSleep(ms) {
9
+ return new Promise((resolve) => setTimeout(resolve, ms));
10
+ }
11
+ function formatError(error) {
12
+ return error instanceof Error ? error.message : String(error);
13
+ }
14
+ class RemoteCollectionDeletePendingError extends Error {
15
+ constructor(collectionName, attempts, lastError) {
16
+ const detail = lastError ? ` Last error: ${formatError(lastError)}` : '';
17
+ super(`Remote collection deletion did not complete for '${collectionName}' after ${attempts} attempt(s).${detail}`);
18
+ this.name = 'RemoteCollectionDeletePendingError';
19
+ this.collectionName = collectionName;
20
+ this.attempts = attempts;
21
+ this.lastError = lastError;
22
+ }
23
+ }
24
+ exports.RemoteCollectionDeletePendingError = RemoteCollectionDeletePendingError;
25
+ async function deleteCollectionWithVerification(vectorDatabase, collectionName, options = {}) {
26
+ const maxAttempts = Math.max(1, Math.floor(options.maxAttempts ?? DEFAULT_MAX_ATTEMPTS));
27
+ const initialBackoffMs = Math.max(0, options.initialBackoffMs ?? DEFAULT_INITIAL_BACKOFF_MS);
28
+ const backoffMultiplier = Math.max(1, options.backoffMultiplier ?? DEFAULT_BACKOFF_MULTIPLIER);
29
+ const sleep = options.sleep ?? defaultSleep;
30
+ if (!await vectorDatabase.hasCollection(collectionName)) {
31
+ return { collectionName, attempts: 0, verifiedAbsent: true };
32
+ }
33
+ let lastError;
34
+ for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
35
+ lastError = undefined;
36
+ try {
37
+ await vectorDatabase.dropCollection(collectionName);
38
+ }
39
+ catch (error) {
40
+ lastError = error;
41
+ }
42
+ try {
43
+ const stillExists = await vectorDatabase.hasCollection(collectionName);
44
+ if (!stillExists) {
45
+ return { collectionName, attempts: attempt, verifiedAbsent: true };
46
+ }
47
+ if (!lastError) {
48
+ lastError = new Error(`dropCollection returned successfully but '${collectionName}' still exists.`);
49
+ }
50
+ }
51
+ catch (error) {
52
+ lastError = error;
53
+ }
54
+ if (attempt < maxAttempts && initialBackoffMs > 0) {
55
+ await sleep(initialBackoffMs * Math.pow(backoffMultiplier, attempt - 1));
56
+ }
57
+ }
58
+ throw new RemoteCollectionDeletePendingError(collectionName, maxAttempts, lastError);
59
+ }
60
+ //# sourceMappingURL=remote-delete.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zokizuan/satori-core",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "Core semantic indexing engine for Satori's insight-first retrieval",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",