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

Class LangChainEmbeddingHelper

embedding/embeddingHelper.py:546–570  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

544
545@singleton
546class LangChainEmbeddingHelper:
547 def __init__(self):
548 # Map{dbId, db}
549 self.dbMap = {}
550
551 def from_documents(self, documents: list[Document], dbId: str, embedding=OpenAIEmbeddings(),
552 persist_directory: str = None):
553 if persist_directory is None:
554 persist_directory = "./embedding" + dbId
555 db = Chroma.from_documents(documents, embedding=embedding, persist_directory=persist_directory)
556 self.dbMap[dbId] = db
557
558 def from_texts(self, texts: list[str], dbId: str, embedding=OpenAIEmbeddings(), persist_directory: str = None):
559 if persist_directory is None:
560 persist_directory = "./embedding" + dbId
561 db = Chroma.from_texts(texts, embedding=embedding, persist_directory=persist_directory)
562 self.dbMap[dbId] = db
563
564 def similarity_search(self, query: str, fileID: str, topK: int = 4) -> list[str]:
565 db = self.dbMap[fileID]
566 docs = db.similarity_search(query, k=topK)
567 texts = []
568 for doc in docs:
569 texts.append(doc.page_content)
570 return texts
571
572
573@singleton

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected