(rel: string, content: string, chunkLines: number, overlap: number)
| 71 | } |
| 72 | |
| 73 | export function chunkFile(rel: string, content: string, chunkLines: number, overlap: number): Chunk[] { |
| 74 | const lines = content.split('\n'); |
| 75 | const out: Chunk[] = []; |
| 76 | for (let i = 0; i < lines.length; i += (chunkLines - overlap)) { |
| 77 | const start = i; |
| 78 | const end = Math.min(i + chunkLines, lines.length); |
| 79 | if (end - start < 5) continue; |
| 80 | const text = lines.slice(start, end).join('\n'); |
| 81 | const hash = createHash('sha1').update(text).digest('hex').slice(0, 12); |
| 82 | out.push({ file: rel, startLine: start + 1, endLine: end, text, hash }); |
| 83 | if (end >= lines.length) break; |
| 84 | } |
| 85 | return out; |
| 86 | } |
| 87 | |
| 88 | export async function ollamaEmbed(baseUrl: string, model: string, texts: string[], signal?: AbortSignal): Promise<number[][]> { |
| 89 | const r = await fetch(`${baseUrl.replace(/\/$/, '')}/api/embed`, { |
no test coverage detected