-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinterface.ts
More file actions
121 lines (106 loc) · 2.61 KB
/
Copy pathinterface.ts
File metadata and controls
121 lines (106 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* Common interface for vector stores.
* Both QdrantVectorStore and SqliteVecClient implement this interface.
*/
export interface VectorStoreSearchResult {
id: string
score: number
vector?: number[]
payload: {
filePath: string
codeChunk: string
startLine: number
endLine: number
segmentHash?: string
}
}
export interface VectorStoreInitResult {
created: boolean
didCleanup: boolean
}
export interface VectorStore {
/**
* Initialize the vector store.
* Creates collection/table if it doesn't exist.
* Returns initialization result with created and cleanup flags.
*/
initialize(): Promise<VectorStoreInitResult>
/**
* Reset the collection by dropping and recreating it.
*/
resetCollection(): Promise<void>
/**
* Upsert points into the vector store.
*/
upsertPoints(
points: Array<{
id: string
vector: number[]
payload: Record<string, any>
}>,
): Promise<void>
/**
* Search for similar vectors.
*
* @param queryVector - The query vector to search for
* @param directoryPrefix - Optional directory prefix to filter results
* @param minScore - Minimum similarity score (0-1, higher is better)
* @param maxResults - Maximum number of results to return
*/
search(
queryVector: number[],
directoryPrefix?: string,
minScore?: number,
maxResults?: number,
): Promise<VectorStoreSearchResult[]>
/**
* Delete points by file path.
*/
deletePointsByFilePath(filePath: string): Promise<void>
/**
* Delete points by multiple file paths.
*/
deletePointsByMultipleFilePaths(filePaths: string[]): Promise<void>
/**
* Delete the entire collection.
*/
deleteCollection(): Promise<void>
/**
* Clear all points from the collection.
*/
clearCollection(): Promise<void>
/**
* Check if the collection exists.
*/
collectionExists(): Promise<boolean>
/**
* Ensure vector dimension matches.
* If not, recreate the collection.
*/
ensureVectorDimension(actualDimension: number): Promise<void>
/**
* Get collection statistics.
* Returns total vectors, unique files, and vector dimension.
*/
getCollectionStats?(): Promise<{
totalVectors: number
uniqueFiles: number
vectorDimension: number
} | null>
}
/**
* Generate a point ID from a segment hash.
* This function is used by both vector stores to ensure consistent IDs.
*/
export function generatePointId(segmentHash: string): string {
const hex = segmentHash.replace(/-/g, "").toLowerCase()
const base = hex.slice(0, 32).padEnd(32, "0")
const sections = [
base.slice(0, 8),
base.slice(8, 12),
base.slice(12, 16),
base.slice(16, 20),
base.slice(20, 32),
]
return sections.join("-")
}