Natural language to mongo retriver #10237
Replies: 1 comment
-
🤖 Hey @lalitbyteiq! Good to see you back. Hope you're coding away to glory! 😎 Yes, you can retrieve data from MongoDB using a query retriever in the LlamaIndex framework. The method for this is called Here is the code for the def _query(self, query: VectorStoreQuery) -> VectorStoreQueryResult:
params: Dict[str, Any] = {
"vector": query.query_embedding,
"path": self._embedding_key,
"k": query.similarity_top_k,
}
if query.filters is not None:
raise ValueError(
"Metadata filters not implemented for azure cosmosdb mongodb yet."
)
query_field = {"$search": {"cosmosSearch": params, "returnStoredSource": True}}
pipeline = [
query_field,
{
"$project": {
"similarityScore": {"$meta": "searchScore"},
"document": "$$ROOT",
}
},
]
logger.debug("Running query pipeline: %s", pipeline)
cursor = self._collection.aggregate(pipeline) # type: ignore
top_k_nodes = []
top_k_ids = []
top_k_scores = []
for res in cursor:
text = res["document"].pop(self._text_key)
score = res.pop("similarityScore")
id = res["document"].pop(self._id_key)
metadata_dict = res["document"].pop(self._metadata_key)
try {
node = metadata_dict_to_node(metadata_dict)
node.set_content(text)
} catch (Exception) {
// NOTE: deprecated legacy logic for backward compatibility
metadata, node_info, relationships = legacy_metadata_dict_to_node(
metadata_dict
)
node = TextNode(
text=text,
id_=id,
metadata=metadata,
start_char_idx=node_info.get("start", None),
end_char_idx=node_info.get("end", None),
relationships=relationships,
)
}
top_k_ids.append(id)
top_k_nodes.append(node)
top_k_scores.append(score)
}
result = VectorStoreQueryResult(
nodes=top_k_nodes, similarities=top_k_scores, ids=top_k_ids
)
logger.debug("Result of query: %s", result)
return result This method is also used by the public Also, the LlamaIndex framework does support other databases apart from MongoDB for data retrieval. It supports TimescaleDB, a time-series database built on PostgreSQL. This is evident from the import statement I hope this helps! If you have any other questions, feel free to ask. Best, SourcesThis response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is there any way to retrieve data from Mongo db not using vector store but as query retriever .
Beta Was this translation helpful? Give feedback.
All reactions