Mongodb Koda Retriever
Koda Retriever + MongoDB + Fireworks: package solution for best RAG data quality
As people are building more advanced abstractions on top of RAG, we can compose that together with MongoDB and Fireworks to provide a turn key solution that provides the best quality out of the box. Koda retriever from LlamaIndex is a good example, it implements hybrid retrieval out of the box, and would only need users to some config tunings on the weight of different search methods to be able to get the best results. In this case, we will make use of
- Fireworks embeddings, reranker and LLMs to drive the ranking end to end
- MongoDB Atlas for embedding features
For more information on how Koda Retriever pack for LlamaIndex works, please check out LlamaIndex's page for Koda Retriever
We will start from the beginning, perform the data import, embed the data, and then use Koda Retriever on top of the imported data
Basic installations
We will install all the relevant dependencies for Fireworks, MongoDB, Koda Retriever
we are going to delete this collection to clean up all the previous documents inserted.
DeleteResult({'n': 18067, 'electionId': ObjectId('7fffffff00000000000001cf'), 'opTime': {'ts': Timestamp(1709534085, 5295), 't': 463}, 'ok': 1.0, '$clusterTime': {'clusterTime': Timestamp(1709534085, 5295), 'signature': {'hash': b'\xac;\x86\x9b\xbe\xb4\xa7\xed\xe6\x03\xc0jY\xb8p\xef\x9a\x05\xe7\xce', 'keyId': 7294687148333072386}}, 'operationTime': Timestamp(1709534085, 5295)}, acknowledged=True) data import
We are going to import from MongoDB's huggingface dataset with 25k restaurants
The Embedding model sees this:
Metadata: _id=>{'$oid': '6095a34a7c34416a90d3206b'}
DogsAllowed=>None
TakeOut=>True
sponsored=>None
review_count=>10
OutdoorSeating=>True
HappyHour=>null
cuisine=>"Tex-Mex"
PriceRange=>1.0
address=>{"building": "627", "coord": [-73.975981, 40.745132], "street": "2 Avenue", "zipcode": "10016"}
restaurant_id=>40366661
menu=>null
attributes=>{"Alcohol": "'none'", "Ambience": "{'romantic': False, 'intimate': False, 'classy': False, 'hipster': False, 'divey': False, 'touristy': False, 'trendy': False, 'upscale': False, 'casual': False}", "BYOB": null, "BestNights": null, "BikeParking": null, "BusinessAcceptsBitcoin": null, "BusinessAcceptsCreditCards": null, "BusinessParking": "None", "Caters": "True", "DriveThru": null, "GoodForDancing": null, "GoodForKids": "True", "GoodForMeal": null, "HasTV": "True", "Music": null, "NoiseLevel": "'average'", "RestaurantsAttire": "'casual'", "RestaurantsDelivery": "True", "RestaurantsGoodForGroups": "True", "RestaurantsReservations": "True", "RestaurantsTableService": "False", "WheelchairAccessible": "True", "WiFi": "'free'"}
name=>"Baby Bo'S Burritos"
borough=>"Manhattan"
stars=>2.5
-----
Content: {"_id": {"$oid": "6095a34a7c34416a90d3206b"}, "DogsAllowed": null, "TakeOut": true, "sponsored": null, "review_count": "10", "OutdoorSeating": true, "HappyHour": "null", "cuisine": "\"Tex-Mex\"", "PriceRange": "1.0", "address": "{\"building\": \"627\", \"coord\": [-73.975981, 40.745132], \"street\": \"2 Avenue\", \"zipcode\": \"10016\"}", "restaurant_id": "40366661", "menu": "null", "attributes": "{\"Alcohol\": \"'none'\", \"Ambience\": \"{'romantic': False, 'intimate': False, 'classy': False, 'hipster': False, 'divey': False, 'touristy': False, 'trendy': False, 'upscale': False, 'casual': False}\", \"BYOB\": null, \"BestNights\": null, \"BikeParking\": null, \"BusinessAcceptsBitcoin\": null, \"BusinessAcceptsCreditCards\": null, \"BusinessParking\": \"None\", \"Caters\": \"True\", \"DriveThru\": null, \"GoodForDancing\": null, \"GoodForKids\": \"True\", \"GoodForMeal\": null, \"HasTV\": \"True\", \"Music\": null, \"NoiseLevel\": \"'average'\", \"RestaurantsAttire\": \"'casual'\", \"RestaurantsDelivery\": \"True\", \"RestaurantsGoodForGroups\": \"True\", \"RestaurantsReservations\": \"True\", \"RestaurantsTableService\": \"False\", \"WheelchairAccessible\": \"True\", \"WiFi\": \"'free'\"}", "name": "\"Baby Bo'S Burritos\"", "borough": "\"Manhattan\"", "stars": 2.5}
We are going to use SentenceSplitter to split the documents. We will also reduce the size to 2.5k documents to make sure this example fits into a free MongoDB Atlas instance
And add the following index in MongoDB Atlas. We will name it vector_index
{
"fields": [
{
"type": "vector",
"path": "embedding",
"numDimensions": 768,
"similarity": "dotProduct"
}
]
}
Using Koda Retriever
With all that preparation work, now we are finally going to show case Koda Retriever!
Koda Retriever has most of the settings prepared out of the box for you, so we can plug the index, llm, reranker and make the example run out of the box. For more advanced settings on how to run KodaRetriever, please check out the guide here
And now we will query the retriever to find some bakery recommendations in Manhattan
Based on the context provided, I would recommend two bakeries in Manhattan. The first one is Lung Moon Bakery, which offers a variety of baked goods such as Stuffed Croissants, Gourmet Doughnuts, Brownies, and Cookie sandwiches with icing in the middle. They have outdoor seating and take-out options available. The second recommendation is Zaro's Bread Basket, which has a selection including Stuffed Croissants, Pecan tart, Chocolate strawberries, and Lemon cupcakes. Zaro's Bread Basket also offers delivery and has a bike parking facility. Both bakeries are rated quite well by their customers.
That is it! A solution with that combines query engine, embedding, llms and reranker all in just a few lines of LlamaIndex code. Fireworks is here to support you for your complete RAG journey, and please let us know if there are any other high quality RAG setups like Koda Retriever that you want us to support in our Discord channel.