-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MongoDB support [VectorDB] [v0: basic RAG] (#1505)
Potentially closes #1412 Add MongoDB as a VectorDB. --------- Co-authored-by: Fabian Valle <[email protected]>
- Loading branch information
1 parent
6435c22
commit 69acd16
Showing
3 changed files
with
416 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# install pymongo - `pip install pymongo` | ||
|
||
from phi.agent import Agent | ||
from phi.knowledge.pdf import PDFUrlKnowledgeBase | ||
import os | ||
#os.environ["OPENAI_API_KEY"] = "" | ||
from phi.vectordb.mongodb import MongoDBVector | ||
|
||
# MongoDB Atlas connection string | ||
""" | ||
Example connection strings: | ||
"mongodb+srv://<username>:<password>@cluster0.mongodb.net/?retryWrites=true&w=majority" | ||
"mongodb://localhost/?directConnection=true" | ||
""" | ||
mdb_connection_string = "" | ||
|
||
knowledge_base = PDFUrlKnowledgeBase( | ||
urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"], | ||
vector_db=MongoDBVector(collection_name="recipes", db_url=mdb_connection_string, wait_until_index_ready=60, wait_after_insert=300), | ||
) #adjust wait_after_insert and wait_until_index_ready to your needs | ||
knowledge_base.load(recreate=True) | ||
|
||
# Create and use the agent | ||
agent = Agent(knowledge_base=knowledge_base, show_tool_calls=True) | ||
agent.print_response("How to make Thai curry?", markdown=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from phi.vectordb.mongodb.mongodb import MongoDBVector | ||
|
||
__all__ = ["MongoDBVector"] |
Oops, something went wrong.