( file: File, progressCallback: (progress: number) => Promise<void> | void )
| 232 | const models = useCachedModels(); |
| 233 | |
| 234 | async function uploadToIndex( |
| 235 | file: File, |
| 236 | progressCallback: (progress: number) => Promise<void> | void |
| 237 | ) { |
| 238 | const txt = await loadFile(file); |
| 239 | const txthash = hashCode(txt || ''); |
| 240 | let maxsteps = 0; |
| 241 | let steps = 0; |
| 242 | //console.log(txt) |
| 243 | console.log(`processing ${file.name}`); |
| 244 | if (txt && documentStore) { |
| 245 | let output: Document[] = []; |
| 246 | if (file.type == 'text/csv') { |
| 247 | output = splitCSVIntoLines(txt).map( |
| 248 | (txtLine, index) => |
| 249 | new Document({ |
| 250 | pageContent: txtLine, |
| 251 | metadata: { |
| 252 | filename: file.name, |
| 253 | source: 'file upload', |
| 254 | line: index, |
| 255 | }, |
| 256 | }) |
| 257 | ); |
| 258 | } else { |
| 259 | output = await splitter.splitDocuments([ |
| 260 | new Document({ |
| 261 | pageContent: txt, |
| 262 | metadata: { |
| 263 | filename: file.name, |
| 264 | source: 'file upload', |
| 265 | }, |
| 266 | }), |
| 267 | ]); |
| 268 | } |
| 269 | |
| 270 | // filter out empty lines etc... |
| 271 | output = output.filter((doc) => doc.pageContent); |
| 272 | |
| 273 | // prepare data (vectorize) for ingestions |
| 274 | maxsteps = output.length * 2 || 1; |
| 275 | //const output = await splitter.createDocuments([txt], metadatas = [{ filename: file.name }]); |
| 276 | const docvecs: idbDocument[] = []; |
| 277 | for (let i = 0; i < output.length; i++) { |
| 278 | const doc = output[i]; |
| 279 | //const uuids = uuidv4() |
| 280 | //doc.metadata['uuid'] = uuid.to |
| 281 | docvecs.push({ |
| 282 | document: doc, |
| 283 | vector: ( |
| 284 | await models.vectorize( |
| 285 | doc.pageContent, |
| 286 | vecStoreUploaderConfigurationState.value.modelName |
| 287 | ) |
| 288 | ).tolist()[0] as number[], |
| 289 | }); |
| 290 | steps += 1; |
| 291 | await progressCallback(steps / maxsteps); |
nothing calls this directly
no test coverage detected