Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/question with knowledge base loading #1435

Open
Pablo-Merino opened this issue Nov 13, 2024 · 3 comments
Open

Issue/question with knowledge base loading #1435

Pablo-Merino opened this issue Nov 13, 2024 · 3 comments
Labels

Comments

@Pablo-Merino
Copy link

Pablo-Merino commented Nov 13, 2024

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

from dotenv import load_dotenv
load_dotenv(override=True)
from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.embedder.openai import OpenAIEmbedder
from phi.knowledge.text import TextKnowledgeBase
from phi.vectordb.lancedb import LanceDb, SearchType
from pathlib import Path

vector_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 loaded
knowledge_base.load(
    recreate=False,
    skip_existing=True
)

agent = Agent(
    model=OpenAIChat(id="gpt-4o"),
    # Add the knowledge base to the agent
    knowledge=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!

@ysolanky
Copy link
Contributor

Hello @Pablo-Merino !

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

Copy link

This issue has been automatically marked as stale due to 14 days of inactivity and will now be closed.

@github-actions github-actions bot added the stale label Dec 16, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 16, 2024
@manthanguptaa manthanguptaa reopened this Dec 16, 2024
@bpsong
Copy link

bpsong commented Dec 20, 2024

I hit the same problem yesterday

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants