diff options
| author | A.J. Shulman <Shulman.aj@gmail.com> | 2024-07-15 13:47:39 -0400 |
|---|---|---|
| committer | A.J. Shulman <Shulman.aj@gmail.com> | 2024-07-15 13:47:39 -0400 |
| commit | 97fdb44133c6aed043f84fd345d5ac57125e5405 (patch) | |
| tree | ddb3b3db0b2f4fc926b33c318fd9b572d871e528 /src/client/views/nodes/ChatBox/vectorstore | |
| parent | ef79b7d617035c52fea159225ba9a39b8222e8f4 (diff) | |
attempt at adding links
Diffstat (limited to 'src/client/views/nodes/ChatBox/vectorstore')
| -rw-r--r-- | src/client/views/nodes/ChatBox/vectorstore/VectorstoreUpload.ts | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/client/views/nodes/ChatBox/vectorstore/VectorstoreUpload.ts b/src/client/views/nodes/ChatBox/vectorstore/VectorstoreUpload.ts index d3b1cb4e7..3a889bff2 100644 --- a/src/client/views/nodes/ChatBox/vectorstore/VectorstoreUpload.ts +++ b/src/client/views/nodes/ChatBox/vectorstore/VectorstoreUpload.ts @@ -16,9 +16,10 @@ export class Vectorstore { private index!: Index; private cohere: CohereClient; private indexName: string = 'pdf-chatbot'; + private id: string; documents: AI_Document[] = []; - constructor() { + constructor(id: string) { const pineconeApiKey = process.env.PINECONE_API_KEY; if (!pineconeApiKey) { throw new Error('PINECONE_API_KEY is not defined.'); @@ -30,6 +31,7 @@ export class Vectorstore { this.cohere = new CohereClient({ token: process.env.COHERE_API_KEY, }); + this.id = id; this.initializeIndex(); } @@ -62,23 +64,28 @@ export class Vectorstore { } async addAIDoc(doc: Doc) { - if (doc[DocData]?.ai_document) { - this.documents.push(convertToAIDocument(JSON.parse(StrCast(doc[DocData].ai_document)))); + if (doc.ai_document) { + if (doc.ai_document === 'IN PROGRESS') { + console.log('Already in progress.'); + return; + } + this.documents.push(convertToAIDocument(JSON.parse(StrCast(doc.ai_document)))); console.log(`Document already added: ${doc.file_name}`); } else { + doc.ai_document = 'IN PROGRESS'; console.log(doc); console.log(PDFCast(doc.data)?.url?.pathname); console.log(CsvCast(doc.data)?.url?.pathname); const local_file_path: string = CsvCast(doc.data)?.url?.pathname ?? PDFCast(doc.data)?.url?.pathname; console.log('Local File Path:', local_file_path); - if (local_file_path) { + if (local_file_path !== undefined || local_file_path !== null || local_file_path !== '') { const { document_json } = await Networking.PostToServer('/createDocument', { file_path: local_file_path }); console.log('Document JSON:', document_json); const ai_document: AI_Document = convertToAIDocument(document_json); this.documents.push(ai_document); await this.indexDocument(ai_document); console.log(`Document added: ${ai_document.file_name}`); - doc[DocData].ai_document = JSON.stringify(document_json); + doc.ai_document = JSON.stringify(document_json); } } } @@ -94,7 +101,7 @@ export class Vectorstore { ({ id: chunk.id, values: chunk.values, - metadata: chunk.metadata as RecordMetadata, + metadata: { ...chunk.metadata, vectorestore_id: this.id } as RecordMetadata, }) as PineconeRecord ); await this.index.upsert(pineconeRecords); @@ -125,6 +132,9 @@ export class Vectorstore { const queryResponse: QueryResponse<RecordMetadata> = await this.index.query({ vector: queryEmbedding, + filter: { + vectorstore_id: this.id, + }, topK, includeValues: true, includeMetadata: true, |
