Processes documents into chunks and creates embeddings.
| 124 | answer: str = Field(description="The current answer based on the context") |
| 125 | |
| 126 | class DocumentProcessor: |
| 127 | """Processes documents into chunks and creates embeddings.""" |
| 128 | |
| 129 | def __init__(self, embedding_model: str = None, chunk_size: int = DEFAULT_CHUNK_SIZE, |
| 130 | chunk_overlap: int = DEFAULT_CHUNK_OVERLAP): |
| 131 | self.text_splitter = RecursiveCharacterTextSplitter( |
| 132 | chunk_size=chunk_size, |
| 133 | chunk_overlap=chunk_overlap |
| 134 | ) |
| 135 | self.embeddings = _get_embeddings(embedding_model) |
| 136 | self.vector_store = None |
| 137 | |
| 138 | def process_documents(self, documents: List[Document]) -> Tuple[List, Any]: |
| 139 | """Split documents and create vector store.""" |
| 140 | splits = self.text_splitter.split_documents(documents) |
| 141 | self.vector_store = FAISS.from_documents(splits, self.embeddings) |
| 142 | return splits, self.vector_store |
| 143 | |
| 144 | class KnowledgeGraph: |
| 145 | """Builds and manages a knowledge graph from document chunks.""" |