Skip to content

Commit

Permalink
Add MongoDB support [VectorDB] [v0: basic RAG] (#1505)
Browse files Browse the repository at this point in the history
Potentially closes #1412

Add MongoDB as a VectorDB.

---------

Co-authored-by: Fabian Valle <[email protected]>
  • Loading branch information
ranfysvalle02 and Fabian Valle authored Jan 7, 2025
1 parent 6435c22 commit 69acd16
Show file tree
Hide file tree
Showing 3 changed files with 416 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cookbook/vectordb/mongodb.py
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)
3 changes: 3 additions & 0 deletions phi/vectordb/mongodb/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from phi.vectordb.mongodb.mongodb import MongoDBVector

__all__ = ["MongoDBVector"]
Loading

0 comments on commit 69acd16

Please sign in to comment.