EventGet 50% off your ticket to MongoDB.local London on October 2. Use code WEB50Learn more >>
MongoDB Developer
PHP
plus
Sign in to follow topics
MongoDB Developer Centerchevron-right
Developer Topicschevron-right
Languageschevron-right
PHPchevron-right

Introducing the Tour Planner With MongoDB Vector Search

Pavel Duchovny5 min read • Published Sep 24, 2024 • Updated Sep 24, 2024
AIAtlasVector SearchPHP
FULL APPLICATION
Facebook Icontwitter iconlinkedin icon
Rate this code example
star-empty
star-empty
star-empty
star-empty
star-empty
social-githubView Code
In today's fast-paced world, planning a trip can often feel like a daunting task. From selecting the perfect destinations to finding the most exciting activities, it can be overwhelming. But what if there was a smarter way to plan your travels? A way that combines leading technology like OpenAI and MongoDB to smarter applications? Welcome to the Tour Planner with MongoDB Vector Search!
A video with the application and solution overview!

The Essence of the Tour Planner

The Tour Planner project is an innovative travel planning application designed to simplify and enhance your travel experience. By leveraging the power of MongoDB Vector Search and integrating with OpenAI, the Tour Planner offers intelligent search and recommendation features with a few lines of code.
Main application page

Key features

Our advanced vector-based similarity search allows you to discover cities that match your interests. Whether you're looking for a city rich in history, a vibrant nightlife, or serene landscapes, our smart search feature will find the perfect destination for you.
Semantic Search with Vectors

2. Personalized points of interest

Gone are the days of generic travel recommendations. With the Tour Planner, you receive personalized points of interest based on your unique preferences. The document model allows developers to store and retrieve specific information crafted from different structures, while still being easily consumed by LLMs.
Planner customized

3. Intelligent trip planning

The integration of OpenAI into our platform takes trip planning to a whole new level. By analyzing your selected destinations and points of interest, our intelligent system generates a detailed itinerary that optimizes your time and enhances your travel experience. All you need to do is sit back and enjoy the journey. This in turn combines AI generated data with our real-time database to search for flights or other specific information for our personalized tour.
Plan built with AI

Why Laravel?

We chose Laravel for its robust and elegant framework that simplifies the development process. Laravel's built-in features, such as a powerful ORM, routing, and authentication, make it an ideal choice for building complex applications quickly and efficiently.

Ease of setup with MongoDB and Laravel OpenAI integrations

Integrating MongoDB and OpenAI with Laravel allows us to build retrieval-augmented generation (RAG) and AI-powered back ends seamlessly. MongoDB's flexible schema and powerful querying capabilities, combined with Laravel's expressive syntax, enable us to implement advanced search functionalities with ease. The integration with OpenAI further enhances our application by providing intelligent recommendations and dynamic trip planning features.
By using Laravel, MongoDB, and OpenAI together, we can create a scalable, efficient, and intelligent back end that leverages the best of modern web development technologies.
The OpenAI package for Laravel is not included by default in Laravel installations. You need to install it separately. Here's how you can add it to your project:
First, you need to install the package using Composer. Run this command in your project directory:
After installation, you should publish the configuration file:
This will create a configuration file at config/openai.php. You'll need to set your OpenAI API key in this file or, preferably, in your .env file:
Once installed and configured, you can use the OpenAI facade in your Laravel application as shown in the previous examples:
In our application, all those steps were performed and are part of the composer.json file.

How it works

The back end of the Tour Planner is powered by Laravel, under the app folder.
Points of interest and city information are stored in a MongoDB collection (points_of_interest) mapped to the following application model:
MongoDB Vector Search handles the complex search queries. When you search for a city or activity, the system generates embeddings based on your input and searches for the best matches within the database.
The results are then augmented with relevant context using OpenAI to create a comprehensive trip plan. The system generates an itinerary that includes flight details, activities, and free time, ensuring every moment of your trip is well-planned.
Since both the format expected and the system prompts specify a JSON output, the LLM returns a predictable flexible JSON that is being downstreamed easily to a frontend UI.

Getting started

To get started with the Tour Planner, you need a few prerequisites:
  • PHP 8.1+
  • MongoDB extension and prerequisites
  • Composer
  • Node.js and npm
  • MongoDB Atlas cluster
  • OpenAI API key
Clone the project on our GitHub repository.

Backend setup (Laravel):

Navigate to the cloned directory:
Install PHP dependencies:
Copy the .env.example file to .env and configure your environment variables:
Generate an application key:
Run database seeders:
This will create two collections under database trip_planner.
  • collection: points_of_interest. Sample document:
  • Collection: air_routes. Sample document:
Create an Atlas Vector Search index on the database: trip_planner collection: points_of_interest. See the guide for more details on how to index fields for vector search.
Index name: vector_index
Start the Laravel development server:

Frontend setup (Vue.js)

Navigate to the frontend directory:
The application should be visible at http://localhost:8080.

Conclusion

The Tour Planner utilizes MongoDB Vector Search to enhance travel planning capabilities. It combines user preferences with data analysis to suggest tailored trip options. This implementation demonstrates the integration of MongoDB, Laravel, and OpenAI technologies to create an advanced search application for travel recommendations.
Ready to start your journey? Dive into our documentation for detailed setup guides, try out MongoDB for yourself at MongoDB Atlas, and explore the project on GitHub. Unlock a new way of travel planning and make your next project with MongoDB.
Top Comments in Forums
There are no comments on this article yet.
Start the Conversation

Facebook Icontwitter iconlinkedin icon
Rate this code example
star-empty
star-empty
star-empty
star-empty
star-empty
Related
News & Announcements

Laravel MongoDB 4.2 Released, With Laravel 11 Support


Aug 28, 2024 | 1 min read
Quickstart

Getting Set Up to Run PHP With MongoDB


Aug 29, 2024 | 12 min read
Article

Handling MongoDB PHP Errors


Aug 28, 2024 | 7 min read
Tutorial

Symfony and MongoDB Workshop: Building a Rental Listing Application


Aug 28, 2024 | 3 min read
Technologies Used
Languages
Technologies
Table of Contents