(self, documents: list[Document], collectionId: Optional[str], embedding: Optional = OpenAIEmbeddings(),
persist_directory: Optional[str] = None)
| 602 | "paragraph is as follows: {}" |
| 603 | |
| 604 | def from_documents(self, documents: list[Document], collectionId: Optional[str], embedding: Optional = OpenAIEmbeddings(), |
| 605 | persist_directory: Optional[str] = None) -> str: |
| 606 | if collectionId is None: |
| 607 | collectionId = self.generated_id() |
| 608 | collection = self.client.get_or_create_collection(collectionId) |
| 609 | idIndex = 0 |
| 610 | |
| 611 | texts = [] |
| 612 | ids = [] |
| 613 | embeddings = [] |
| 614 | for document in documents: |
| 615 | text = document.page_content |
| 616 | texts.append(text) |
| 617 | embeddings.append(self.summaryEmbedding(text)) |
| 618 | ids.append("id" + str(idIndex)) |
| 619 | idIndex += 1 |
| 620 | |
| 621 | collection.add( |
| 622 | documents=texts, |
| 623 | embeddings=embeddings, |
| 624 | # metadatas=[{"source": "notion"}, {"source": "google-docs"}], # filter on these! |
| 625 | ids=ids, |
| 626 | ) |
| 627 | |
| 628 | self.collectionMap[collectionId] = collection |
| 629 | self.idIndexMap[collectionId] = idIndex |
| 630 | return collectionId |
| 631 | |
| 632 | def from_texts(self, texts: list[str], collectionId: Optional[str] = None, embedding: Optional = OpenAIEmbeddings(), |
| 633 | persist_directory: Optional[str] = None) -> str: |
no test coverage detected