Deepseek R1 Rag Pipeline With Mongodb
agentsartificial-intelligencellmsmongodb-genai-showcasenotebooksgenerative-airag
Export
DeepSeek and MongoDB For Movie Recommendation System
Install Libaries and Set Environment Variables
[ ]
[2]
Step 1: Data Loading
[3]
sample_mflix.embedded_movies.json: 0%| | 0.00/42.3M [00:00<?, ?B/s]
Generating train split: 0%| | 0/1500 [00:00<?, ? examples/s]
[4]
Number of missing values in each column after removal: plot 0 runtime 14 genres 0 fullplot 0 directors 12 writers 13 countries 0 poster 78 languages 1 cast 1 title 0 num_mflix_comments 0 rated 279 imdb 0 awards 0 type 0 metacritic 893 plot_embedding 1 dtype: int64
[24]
Step 2: Generating Embeddings
[55]
[6]
Step 3: MongoDB (Operational and Vector Database)
MongoDB acts as both an operational and a vector database for the RAG system. MongoDB Atlas specifically provides a database solution that efficiently stores, queries and retrieves vector embeddings.
Creating a database and collection within MongoDB is made simple with MongoDB Atlas.
- First, register for a MongoDB Atlas account. For existing users, sign into MongoDB Atlas.
- Follow the instructions. Select Atlas UI as the procedure to deploy your first cluster.
Follow MongoDB’s steps to get the connection string from the Atlas UI. After setting up the database and obtaining the Atlas cluster connection URI, securely store the URI within your development environment.
[7]
Enter your MONGO URI: ··········
[8]
[9]
Connection to MongoDB successful
[10]
DeleteResult({'n': 0, 'electionId': ObjectId('7fffffff000000000000003c'), 'opTime': {'ts': Timestamp(1738352202, 1), 't': 60}, 'ok': 1.0, '$clusterTime': {'clusterTime': Timestamp(1738352202, 1), 'signature': {'hash': b'\xe4\xa5\xe1\x04\xcd\xc6\xcf\x8aI\xe2\xbd:\xc5\xf6\xa1\xa1Jk\xf6\xea', 'keyId': 7421923411288391683}}, 'operationTime': Timestamp(1738352202, 1)}, acknowledged=True) Step 4: Data Ingestion
[11]
Data ingestion into MongoDB completed
Step 5: Vector Index Creation
[12]
[13]
[14]
[15]
[16]
Creating index 'vector_index'... Waiting for 30 seconds to allow index 'vector_index' to be created... 30-second wait completed for index 'vector_index'.
'vector_index'
Step 6: Vector Search Function
[48]
Step 7: Semantic Search
[44]
Top 5 results for query 'What are the some interesting action movies to watch that include business?': Title: Shanghai Express, Score: 0.7532 Title: Grindhouse, Score: 0.7137 Title: Crime Story, Score: 0.7058 Title: The Accidental Spy, Score: 0.6996 Title: Hand Gun, Score: 0.6962
Step 8: Retrieval Augmented Generation(RA)
Load DeepSeek model from Hugging Face
[ ]
[66]
[67]
Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.
<|begin▁of▁sentence|>Query: What are the some interesting action movies to watch that include business?
Continue to answer the query by using the Search Results:
[{'genres': ['Action', 'Comedy', 'Western'], 'fullplot': "Multi-genre flick (western, martial arts, comedy, adventure, etc.) with an all-star cast about a man who returns to his home town, buys everything in sight, and tries to improve its municipal (and his personal) profits by sabotaging a train so the passengers all have to stop in his town and spend lots o' money! Throw in various subplots involving some Japanese swordsmen, some bungling bankrobbers (one of whom is the head of security), and a gang of no-goods who try to mess up the town.", 'title': 'Shanghai Express', 'score': 0.7531864643096924}, {'genres': ['Action', 'Horror', 'Thriller'], 'fullplot': 'A double-bill of thrillers that recall both filmmakers\' favorite exploitation films. "Grindhouse" (a downtown movie theater in disrepair since its glory days as a movie palace known for "grinding out" non-stop double-bill programs of B-movies) is presented as one full-length feature comprised of two individual films helmed separately by each director. "Death Proof," is a rip-roaring slasher flick where the killer pursues his victims with a car rather than a knife, while "Planet Terror" shows us a view of the world in the midst of a zombie outbreak. The films are joined together by clever faux trailers that recall the \'50s exploitation drive-in classics.', 'title': 'Grindhouse', 'score': 0.713742733001709}, {'genres': ['Action', 'Crime', 'Drama'], 'fullplot': "A dark and handsome true-crime thriller about kidnapping and police corruption in Hong Kong. Once of Jackie Chan's most serious roles, but still overflowing with spectacular acrobatic sequences.", 'title': 'Crime Story', 'score': 0.7057880163192749}, {'genres': ['Action', 'Comedy', 'Thriller'], 'fullplot': 'This action movie unfolds with the story of Bei, a salesman at a workout equipment store, who harbors dreams of adventures. It all starts when on one normal dull day, Bei follows his instincts to trail two suspicious looking men into an alley. When he realizes that these men are robbing a jewelry store, he jumps into action to foil their plans. Soon after Bei meets Liu, a private investigator who convinces Bei that he may be the long-lost son of a rich Korean businessman. In no time, Bei is on his way to fulfill his dreams of adventure and fortune travelling to Korea and even exotic Turkey. As Bei is drawn deeper into the game of cat and mouse, he realizes he has become the key to locating a lung cancer virus. With an assortment of characters fighting him along the way, will Bei succeed in finding the virus himself?', 'title': 'The Accidental Spy', 'score': 0.6996449828147888}, {'genres': ['Action', 'Crime', 'Thriller'], 'fullplot': "It's _The Good, the Bad and the Ugly (1966)_ meets Simple Men (1992). George is a small-time crook. His brother Michael makes a living scamming the elderly by selling them nonexistent burial plots. When their father steals half a million dollars, the brothers find themselves on the run from the police and a local crime boss. But when Dad is killed, George and Michael have to team up to find the hidden loot. fix it to look like this: It's _Buono, il brutto, il cattivo, Il (1966)_ meets Simple Men (1992). George is a small-time crook. His brother Michael makes a living scamming the elderly by selling them nonexistent burial plots. When their father steals half a million dollars, the brothers find themselves on the run from the police and a local crime boss. But when Dad is killed, George and Michael have to team up to find the hidden loot.", 'title': 'Hand Gun', 'score': 0.6962246894836426}]. The Search Results: 10 results. First result: 10 results. First result has 10 entries. The first result is a list of 10 search results, each being a dictionary with 'genres', 'fullplot', 'title', and 'score' keys.
The second result is a list of 10 search results, each being a dictionary with 'genres', 'fullplot', 'title', and 'score' keys.
The third result is a list of 10 search results, each being a dictionary with 'genres', 'fullplot', 'title', and 'score' keys.
The fourth result is a list of 10 search results, each being a dictionary with 'genres', 'fullplot', 'title', and 'score' keys.
The fifth result is a list of 10 search results, each being a dictionary with 'genres', 'fullplot', 'title', and 'score' keys.
The sixth result is a list of 10 search results, each being a dictionary with 'genres', 'fullplot', 'title', and 'score' keys.
The seventh result is a list of 10 search results, each being a dictionary with 'genres', 'fullplot', 'title', and 'score' keys.
The eighth result is a list of 10 search results, each being a dictionary with 'genres', 'fullplot', 'title', and 'score' keys.
The ninth result is a list of 10 search results, each being a dictionary with 'genres', 'fullplot', 'title', and 'score' keys.
The tenth result is a list of 10 search results, each being a dictionary with 'genres', 'fullplot', 'title', and 'score' keys.
So, the user is looking for some interesting action movies that include business. They probably want to watch something that's both thrilling and has a business aspect, maybe something that combines both elements.
Looking at the genres, the user wants to include business. So, the genres that involve business would be Action, Business, Crime, etc. Looking at the genres in the results, Action is present in several, and Business is also present in a few.
So, the user probably wants to watch an action movie that also deals with business-related topics, maybe business-related plot points, or business-related characters.
Looking at the titles, some of them are "Shanghai Express", "Grindhouse", "Crime Story", "The Accidental Spy", "Hand Gun". None of these are business-related, so perhaps the user wants to watch an action movie with a business twist.
Wait, maybe the user is looking for an action movie that also has a business component, like a business-related plot or character. So, perhaps the genres should include Action, Business, and another category.
Looking at the results, "The Good, the Bad and the Ugly" is a crime thriller, and "Fix it" is a crime thriller as well. So, perhaps the user is looking for a crime thriller that has a business twist.
Looking at "The Good, the Bad and the Ugly" and "Fix it", both are crime thrillers. "The Good, the Bad and the Ugly" is 1966, "Fix it" is 1992. Both are crime thrillers, but "Fix it" is a bit more of a crime thriller with a business element. The title is "Fix it, il brutto, il cattivo, Il (1966)", which seems to be a crime thriller with a mix of business and crime elements.
Alternatively, looking at "Hand Gun", which is a crime thriller, but it's a bit of a different story.
Looking back at the movies:
- "The Good, the Bad and the Ugly": A crime thriller where the main character is a crook, and the brothers are trying to fix something, maybe a business issue. The title is "Fix it, il brutto, il cattivo, Il (1966)".
- "Hand Gun": Another crime thriller, but it's more of a psychological thriller. The title is "Hand Gun", which is 1966.
So, "The Good, the Bad and the Ugly" seems like a better fit because it's a crime thriller with a business element, perhaps in the sense that the main character is involved in a business-related plot.
Alternatively, maybe "The Accidental Spy" is an action movie with a business twist. Let me check its genre. "The Accidental Spy" is Action, Comedy, Thriller. So, it's more of an action-comedy-thriller.
But the user is looking for an action movie that includes business. So, perhaps "The Good, the Bad and the Ugly" is a better fit
[ ]