Comments (1)
Yes, you can use multiple collections from MongoDB to retrieve data. To achieve this, you can extend the MongoDBAtlasVectorSearch
class to support multiple collections. Here is an example of how you might modify the class:
class MongoDBAtlasVectorSearch(VectorStore):
def __init__(
self,
mongodb_client: Optional[Any] = None,
db_name: str = "default_db",
collection_names: List[str] = ["default_collection"],
index_name: str = "default",
id_key: str = "id",
embedding_key: str = "embedding",
text_key: str = "text",
metadata_key: str = "metadata",
insert_kwargs: Optional[Dict] = None,
**kwargs: Any,
) -> None:
import_err_msg = "`pymongo` package not found, please run `pip install pymongo`"
try:
from importlib.metadata import version
from pymongo import MongoClient
from pymongo.driver_info import DriverInfo
except ImportError:
raise ImportError(import_err_msg)
if mongodb_client is not None:
self._mongodb_client = cast(MongoClient, mongodb_client)
else:
if "MONGO_URI" not in os.environ:
raise ValueError(
"Must specify MONGO_URI via env variable "
"if not directly passing in client."
)
self._mongodb_client = MongoClient(
os.environ["MONGO_URI"],
driver=DriverInfo(name="llama-index", version=version("llama-index")),
)
self._collections = {name: self._mongodb_client[db_name][name] for name in collection_names}
self._current_collection = self._collections[collection_names[0]]
self._index_name = index_name
self._embedding_key = embedding_key
self._id_key = id_key
self._text_key = text_key
self._metadata_key = metadata_key
self._insert_kwargs = insert_kwargs or {}
def switch_collection(self, collection_name: str) -> None:
if collection_name in self._collections:
self._current_collection = self._collections[collection_name]
else:
raise ValueError(f"Collection {collection_name} not found.")
# Modify methods to use self._current_collection instead of self._collection
This modification allows you to switch between multiple collections using the switch_collection
method. You would also need to adjust your methods to use self._current_collection
instead of self._collection
[1][2].
To continue talking to Dosu, mention @dosu.
from llama_index.
Related Issues (20)
- [Feature Request]: Convert TransformQueryEngine to use Workflows
- [Feature Request]: Convert BaseQueryEngine to extend workflows
- [Feature Request]: Convert CitationQueryEngine to use Workflows
- [Feature Request]: Create a WorkflowQueryEngine for custom query engines that wrap existing workflows
- [Feature Request]: Convert CustomQueryEngine to use workflows
- [Feature Request]: Create a stream agent + workflows example
- [Feature Request]: Allow streaming of progress during workflow execution
- [Question]: How can I combine Vector DB and a new query engine? HOT 1
- [Question]: Less context than similarity_top_k HOT 3
- [Feature Request]:
- [Question]: Ingestion Pipelines and Workflows? HOT 2
- [Bug]: poetry add llama-index failing for v0.10.65 HOT 6
- [Bug]: impossible to use PDfReader with an S3 file because of Path() casting HOT 1
- [Bug]: impossible to use PDfReader with an S3 file because of Path() casting HOT 1
- [Question]: How to run HuggingFaceEmbedding on multiple available GPUs? HOT 1
- [Question]: HOT 2
- [Question]: Constructing hybrid indices with Qdrant. HOT 10
- [Bug]: NeptuneAnalyticsPropertyGraphStore incorrectly assigning the embedding to the chunk instead of the entity HOT 2
- [Question]: Data disappear after build vector store with VectorStoreIndex.from_documents() HOT 6
- [Bug]: VectorStoreIndex.build_index_from_nodes() missing 1 required positional argument: 'self' HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from llama_index.