(self, texts: list[str], collectionId: Optional[str] = None, embedding: Optional = OpenAIEmbeddings(),
persist_directory: Optional[str] = None)
| 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: |
| 634 | if collectionId is None: |
| 635 | collectionId = self.generated_id() |
| 636 | collection = self.client.get_or_create_collection(collectionId) |
| 637 | idIndex = 0 |
| 638 | |
| 639 | ids = [] |
| 640 | embeddings = [] |
| 641 | for text in texts: |
| 642 | embeddings.append(self.summaryEmbedding(text)) |
| 643 | ids.append("id" + str(idIndex)) |
| 644 | idIndex += 1 |
| 645 | |
| 646 | collection.add( |
| 647 | documents=texts, |
| 648 | embeddings=embeddings, |
| 649 | # metadatas=[{"source": "notion"}, {"source": "google-docs"}], # filter on these! |
| 650 | ids=ids, # unique for each doc |
| 651 | ) |
| 652 | |
| 653 | self.collectionMap[collectionId] = collection |
| 654 | self.idIndexMap[collectionId] = idIndex |
| 655 | return collectionId |
| 656 | |
| 657 | def similarity_search(self, query: str, collectionId: str, topK: int = 4) -> list[str]: |
| 658 | if collectionId not in self.collectionMap.keys(): |
no test coverage detected