Example

knowledge_base.py
from phi.knowledge.text import DocxKnowledgeBase
from phi.vectordb.pgvector import PgVector

from resources import vector_db

knowledge_base = DocxKnowledgeBase(
    path="data/docs",
    # Table name: ai.docx_documents
    vector_db=PgVector(
        table_name="docx_documents",
        db_url=vector_db.get_db_connection_local(),
    ),
)

DocxKnowledgeBase Params

ParameterTypeDefaultDescription
pathUnion[str, Path]-Path to text files. Can point to a single docx file or a directory of docx files.
formatsList[str][".doc", ".docx"]Formats accepted by this knowledge base.
readerDocxReaderDocxReader()A DocxReader that converts the docx files into Documents for the vector database.

AgentKnowledge Params

DocxKnowledgeBase is a subclass of the AgentKnowledge class and has access to the same params

ParameterTypeDefaultDescription
readerOptional[Reader]NoneReader to read the documents
vector_dbOptional[VectorDb]NoneVector db to store the knowledge base
num_documentsint2Number of relevant documents to return on search
optimize_onOptional[int]1000Number of documents to optimize the vector db on
driverstr"knowledge"Driver for the Assistant knowledge