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)
| 142 | return list_of_documents |
| 143 | |
| 144 | def 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 |
no test coverage detected