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

Method from_documents

embedding/embeddingHelper.py:604–630  ·  view source on GitHub ↗
(self, documents: list[Document], collectionId: Optional[str], embedding: Optional = OpenAIEmbeddings(),
                       persist_directory: Optional[str] = None)

Source from the content-addressed store, hash-verified

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:

Callers 3

add_fileMethod · 0.45
_embeddingsMethod · 0.45
from_documentsMethod · 0.45

Calls 3

generated_idMethod · 0.95
summaryEmbeddingMethod · 0.95
addMethod · 0.80

Tested by

no test coverage detected