MCPcopy Create free account
hub / github.com/SecureAI-Tools/SecureAI-Tools / indexDocument

Function indexDocument

apps/web/lib/fe/components/chat.tsx:483–525  ·  view source on GitHub ↗
({
  collectionId,
  doc,
  onGeneratedChunk,
}: {
  collectionId: Id<DocumentCollectionResponse>,
  doc: DocumentsWithIndexingStatus;
  onGeneratedChunk: (chunk: StreamChunkResponse) => void;
})

Source from the content-addressed store, hash-verified

481};
482
483const indexDocument = async ({
484 collectionId,
485 doc,
486 onGeneratedChunk,
487}: {
488 collectionId: Id<DocumentCollectionResponse>,
489 doc: DocumentsWithIndexingStatus;
490 onGeneratedChunk: (chunk: StreamChunkResponse) => void;
491}): Promise<void> => {
492 return new Promise((resolve, reject) => {
493 if (doc.indexingStatus === DocumentIndexingStatus.INDEXED) {
494 resolve();
495 return;
496 }
497
498 postStreaming<{}>({
499 input: documentCollectionDocumentIndexApiPath(
500 collectionId,
501 Id.from(doc.id),
502 ),
503 req: {},
504 onGeneratedChunk: (chunk) => {
505 let parsedResponses = [];
506 try {
507 const lines = chunk.split("\n").filter((l) => !isEmpty(l));
508 parsedResponses = lines.map((line) => JSON.parse(line));
509 } catch (e) {
510 console.log("could not parse stream chunk response", chunk, e);
511 }
512 parsedResponses.forEach((r) => {
513 if (r.error) {
514 reject(r.error);
515 }
516
517 onGeneratedChunk(r);
518 });
519 },
520 onFinish: () => {
521 resolve();
522 },
523 });
524 });
525};
526
527const toCitationMap = (
528 citations: CitationResponse[] | undefined,

Callers 1

indexDocumentsFunction · 0.85

Calls 4

postStreamingFunction · 0.90
isEmptyFunction · 0.90
fromMethod · 0.45

Tested by

no test coverage detected