MCPcopy Create free account
hub / github.com/CL-lau/SQL-GPT / from_texts

Method from_texts

embedding/embeddingHelper.py:632–655  ·  view source on GitHub ↗
(self, texts: list[str], collectionId: Optional[str] = None, embedding: Optional = OpenAIEmbeddings(),
                   persist_directory: Optional[str] = None)

Source from the content-addressed store, hash-verified

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():

Callers 2

add_file_by_textsMethod · 0.45
from_textsMethod · 0.45

Calls 3

generated_idMethod · 0.95
summaryEmbeddingMethod · 0.95
addMethod · 0.80

Tested by

no test coverage detected