MCPcopy Create free account
hub / github.com/AQ-MedAI/MedMemoryBench / encode_documents

Function encode_documents

methods/self_rag.py:144–168  ·  view source on GitHub ↗

Encodes a PDF document into a vector store using hypothetical prompt embeddings. Args: documents: The documents to be encoded. chunk_size: The size of each text chunk. chunk_overlap: The overlap between consecutive chunks. embedding_model: Optional embedding

(documents, chunk_size=4096, chunk_overlap=200, embedding_model=None)

Source from the content-addressed store, hash-verified

142 return list_of_documents
143
144def encode_documents(documents, chunk_size=4096, chunk_overlap=200, embedding_model=None):
145 """
146 Encodes a PDF document into a vector store using hypothetical prompt embeddings.
147
148 Args:
149 documents: The documents to be encoded.
150 chunk_size: The size of each text chunk.
151 chunk_overlap: The overlap between consecutive chunks.
152 embedding_model: Optional embedding model name.
153
154 Returns:
155 A FAISS vector store containing the encoded book content.
156 """
157 # Split documents into chunks
158 text_splitter = RecursiveCharacterTextSplitter(
159 chunk_size=chunk_size, chunk_overlap=chunk_overlap, length_function=len
160 )
161 texts = text_splitter.split_documents(documents)
162 cleaned_texts = replace_t_with_space(texts)
163
164 # Create embeddings and vector store
165 embeddings = _get_openai_embeddings(embedding_model)
166 vectorstore = FAISS.from_documents(cleaned_texts, embeddings)
167
168 return vectorstore
169
170
171

Callers 1

__init__Method · 0.85

Calls 2

replace_t_with_spaceFunction · 0.85
_get_openai_embeddingsFunction · 0.85

Tested by

no test coverage detected