@liendev/core 0.21.0 → 0.23.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.
@@ -1,25 +1,49 @@
1
1
  import { SearchResult, VectorDBInterface } from './types.js';
2
2
  import { ChunkMetadata } from '../indexer/types.js';
3
+ /**
4
+ * Validate filter options for buildBaseFilter.
5
+ *
6
+ * This is a separate function to enable unit testing of validation logic.
7
+ * The validations ensure that conflicting options are not used together.
8
+ *
9
+ * @param options - Filter options to validate
10
+ * @throws Error if conflicting options are detected
11
+ */
12
+ export declare function validateFilterOptions(options: {
13
+ repoIds?: string[];
14
+ branch?: string;
15
+ includeCurrentRepo?: boolean;
16
+ }): void;
3
17
  /**
4
18
  * QdrantDB implements VectorDBInterface using Qdrant vector database.
5
19
  *
6
20
  * Features:
7
21
  * - Multi-tenant support via payload filtering (orgId/repoId)
22
+ * - Branch and commit isolation for PR workflows
8
23
  * - Collection naming: `lien_org_{orgId}`
9
24
  * - Cross-repo search by omitting repoId filter
10
25
  * - Tenant isolation via orgId filtering
26
+ * - Point ID generation includes branch/commit to prevent collisions
27
+ *
28
+ * Data Isolation:
29
+ * All queries are filtered by orgId, repoId, branch, and commitSha by default.
30
+ * This ensures that different branches and commits have isolated data, preventing
31
+ * PRs from overwriting each other's indices. Use cross-repo methods (searchCrossRepo,
32
+ * scanCrossRepo) to query across repositories within an organization.
11
33
  */
12
34
  export declare class QdrantDB implements VectorDBInterface {
13
35
  private client;
14
36
  private collectionName;
15
37
  private orgId;
16
38
  private repoId;
39
+ private branch;
40
+ private commitSha;
17
41
  private initialized;
18
42
  readonly dbPath: string;
19
43
  private lastVersionCheck;
20
44
  private currentVersion;
21
45
  private payloadMapper;
22
- constructor(url: string, apiKey: string | undefined, orgId: string, projectRoot: string);
46
+ constructor(url: string, apiKey: string | undefined, orgId: string, projectRoot: string, branch: string, commitSha: string);
23
47
  /**
24
48
  * Extract repository identifier from project root.
25
49
  * Uses project name + path hash for stable, unique identification.
@@ -27,17 +51,87 @@ export declare class QdrantDB implements VectorDBInterface {
27
51
  private extractRepoId;
28
52
  /**
29
53
  * Generate a unique point ID from chunk metadata.
30
- * Uses hash of file path + line range for stable identification.
54
+ * Uses hash of file path + line range + branch + commitSha for stable identification.
55
+ * Includes branch/commit to prevent ID collisions across branches.
56
+ *
57
+ * **Hash Algorithm Choice:**
58
+ * Uses MD5 for performance and collision likelihood acceptable for this use case.
59
+ * - MD5 is deprecated for cryptographic purposes but suitable for non-security ID generation
60
+ * - Collision probability is extremely low: ~1 in 2^64 for random inputs
61
+ * - Input includes file path, line range, branch, and commit SHA, making collisions
62
+ * even less likely in practice
63
+ * - For typical codebases (thousands to hundreds of thousands of chunks), collision risk
64
+ * is negligible
65
+ * - If scaling to millions of chunks across many repos, consider upgrading to SHA-256
66
+ * for additional collision resistance (at ~10% performance cost)
31
67
  */
32
68
  private generatePointId;
69
+ /**
70
+ * Build base filter for Qdrant queries.
71
+ * Uses builder pattern to simplify filter construction.
72
+ *
73
+ * **Important constraints:**
74
+ * - `includeCurrentRepo` and `repoIds` are mutually exclusive.
75
+ * - `includeCurrentRepo` defaults to `true` when `undefined` (treats `undefined` as "enabled").
76
+ * - To use `repoIds` for cross-repo queries, you must explicitly pass `includeCurrentRepo: false`.
77
+ * - The `branch` parameter can only be used when `includeCurrentRepo` is explicitly `false`.
78
+ * When `includeCurrentRepo` is enabled (default), branch is automatically included via
79
+ * the current repo context (`addRepoContext`).
80
+ *
81
+ * @param options - Filter options
82
+ * @param options.includeCurrentRepo - Whether to filter by current repo context (default: true when undefined).
83
+ * Must be explicitly `false` to use `repoIds` or `branch` parameters.
84
+ * @param options.repoIds - Repository IDs to filter by (requires `includeCurrentRepo: false`).
85
+ * @param options.branch - Branch name to filter by (requires `includeCurrentRepo: false`).
86
+ * @returns Qdrant filter object
87
+ */
88
+ private buildBaseFilter;
89
+ /**
90
+ * Map Qdrant scroll results to SearchResult format.
91
+ *
92
+ * Note: Scroll/scan operations do not compute semantic similarity scores.
93
+ * For these results, score is always 0 and relevance is set to 'not_relevant'
94
+ * to indicate that the results are unscored (not that they are useless).
95
+ */
96
+ private mapScrollResults;
97
+ /**
98
+ * Execute a scroll query with error handling.
99
+ */
100
+ private executeScrollQuery;
33
101
  initialize(): Promise<void>;
102
+ /**
103
+ * Validate batch input arrays have matching lengths.
104
+ */
105
+ private validateBatchInputs;
106
+ /**
107
+ * Prepare Qdrant points from vectors, metadatas, and contents.
108
+ */
109
+ private preparePoints;
34
110
  insertBatch(vectors: Float32Array[], metadatas: ChunkMetadata[], contents: string[]): Promise<void>;
35
111
  search(queryVector: Float32Array, limit?: number, _query?: string): Promise<SearchResult[]>;
36
112
  /**
37
113
  * Search across all repos in the organization (cross-repo search).
38
- * Omits repoId filter to enable cross-repo queries.
114
+ *
115
+ * - Omits repoId filter by default to enable true cross-repo queries.
116
+ * - When repoIds are provided, restricts results to those repositories only.
117
+ * - When branch is omitted, returns chunks from all branches and commits
118
+ * (including historical PR branches and stale commits).
119
+ * - When branch is provided, filters by branch name only and still returns
120
+ * chunks from all commits on that branch across the selected repos.
121
+ *
122
+ * This is a low-level primitive for cross-repo augmentation. Higher-level
123
+ * workflows (e.g. \"latest commit only\") should be built on top of this API.
124
+ *
125
+ * @param queryVector - Query vector for semantic search
126
+ * @param limit - Maximum number of results to return (default: 5)
127
+ * @param options - Optional search options
128
+ * @param options.repoIds - Repository IDs to filter by (optional)
129
+ * @param options.branch - Branch name to filter by (optional)
39
130
  */
40
- searchCrossRepo(queryVector: Float32Array, limit?: number, repoIds?: string[]): Promise<SearchResult[]>;
131
+ searchCrossRepo(queryVector: Float32Array, limit?: number, options?: {
132
+ repoIds?: string[];
133
+ branch?: string;
134
+ }): Promise<SearchResult[]>;
41
135
  scanWithFilter(options: {
42
136
  language?: string;
43
137
  pattern?: string;
@@ -49,13 +143,23 @@ export declare class QdrantDB implements VectorDBInterface {
49
143
  }): Promise<SearchResult[]>;
50
144
  /**
51
145
  * Scan with filter across all repos in the organization (cross-repo).
52
- * Omits repoId filter to enable cross-repo queries.
146
+ *
147
+ * - Omits repoId filter by default to enable true cross-repo scans.
148
+ * - When repoIds are provided, restricts results to those repositories only.
149
+ * - When branch is omitted, returns chunks from all branches and commits
150
+ * (including historical PR branches and stale commits).
151
+ * - When branch is provided, filters by branch name only and still returns
152
+ * chunks from all commits on that branch across the selected repos.
153
+ *
154
+ * Like searchCrossRepo, this is a low-level primitive. Higher-level behavior
155
+ * such as \"latest commit only\" should be implemented in orchestrating code.
53
156
  */
54
157
  scanCrossRepo(options: {
55
158
  language?: string;
56
159
  pattern?: string;
57
160
  limit?: number;
58
161
  repoIds?: string[];
162
+ branch?: string;
59
163
  }): Promise<SearchResult[]>;
60
164
  querySymbols(options: {
61
165
  language?: string;
@@ -64,6 +168,16 @@ export declare class QdrantDB implements VectorDBInterface {
64
168
  limit?: number;
65
169
  }): Promise<SearchResult[]>;
66
170
  clear(): Promise<void>;
171
+ /**
172
+ * Clear all data for a specific branch (all commits).
173
+ *
174
+ * Qdrant-only helper: this is not part of the generic VectorDBInterface and
175
+ * is intended for cloud/PR workflows where multiple commits exist per branch.
176
+ * LanceDB and other backends do not implement this method.
177
+ *
178
+ * @param branch - Branch name to clear (defaults to current branch)
179
+ */
180
+ clearBranch(branch?: string): Promise<void>;
67
181
  deleteByFile(filepath: string): Promise<void>;
68
182
  updateFile(filepath: string, vectors: Float32Array[], metadatas: ChunkMetadata[], contents: string[]): Promise<void>;
69
183
  hasData(): Promise<boolean>;
@@ -1 +1 @@
1
- {"version":3,"file":"qdrant.d.ts","sourceRoot":"","sources":["../../src/vectordb/qdrant.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAOpD;;;;;;;;GAQG;AACH,qBAAa,QAAS,YAAW,iBAAiB;IAChD,OAAO,CAAC,MAAM,CAAe;IAC7B,OA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