You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! I'm trying to use the TextKnowledgeBase with LanceDB, to load the FAQ content I have saved as TXT files. This is the code I'm using
fromdotenvimportload_dotenvload_dotenv(override=True)
fromphi.agentimportAgentfromphi.model.openaiimportOpenAIChatfromphi.embedder.openaiimportOpenAIEmbedderfromphi.knowledge.textimportTextKnowledgeBasefromphi.vectordb.lancedbimportLanceDb, SearchTypefrompathlibimportPathvector_db=LanceDb(
table_name="wak_faq",
uri="./lancedb",
search_type=SearchType.hybrid,
embedder=OpenAIEmbedder(model="text-embedding-3-large"),
)
knowledge_base=TextKnowledgeBase(
path=Path("./faq_text"),
vector_db=vector_db,
)
# Comment out after first run as the knowledge base is loadedknowledge_base.load(
recreate=False,
skip_existing=True
)
agent=Agent(
model=OpenAIChat(id="gpt-4o"),
# Add the knowledge base to the agentknowledge=knowledge_base,
show_tool_calls=True,
markdown=True,
add_context=True
)
agent.print_response("what payment methods do you accept?", stream=True)
This code is supposed to run on a Lambda function, btw.
The issue I have is that I have uncommented the knowledge_base.load() line on the first run. This creates all the LanceDB files/indexes and the question to the agent works fine.
However, as stated in the docs, I comment the load() line after that first run, and then the agent no longer works.
I figured that the knowledge base needs to be loaded at least once every execution (which I don't think it's a good pattern for a Lambda function).
My issue/question is:
Am I using this correctly? Is this the expected functionality?
How could I generate the vector store and have it work without the lengthy loading process?
Thanks a lot! Have a great day!
The text was updated successfully, but these errors were encountered:
Thanks for sharing your code! Your Agent config looks great. Ideally the knowledge.load() should be commented out after the vector db has been populated. But since you have recreate=False and skip_existing=True params set, the database should not be loaded again. But I just tested LanceDb and there seems to be a bug that is causing it to load the documents every time. Sorry about that. I am going to push out a fix
Hello! I'm trying to use the
TextKnowledgeBase
with LanceDB, to load the FAQ content I have saved as TXT files. This is the code I'm usingThis code is supposed to run on a Lambda function, btw.
The issue I have is that I have uncommented the
knowledge_base.load()
line on the first run. This creates all the LanceDB files/indexes and the question to the agent works fine.However, as stated in the docs, I comment the
load()
line after that first run, and then the agent no longer works.I figured that the knowledge base needs to be loaded at least once every execution (which I don't think it's a good pattern for a Lambda function).
My issue/question is:
Thanks a lot! Have a great day!
The text was updated successfully, but these errors were encountered: