EventoObtenha 50% de desconto no seu ingresso para MongoDB.local Londres em outubro 2. Use o código WEB50Saiba mais >>
Desenvolvedor MongoDB
Central de desenvolvedor do MongoDBchevron-right
Idiomaschevron-right
PHPchevron-right

Introducing the Tour Planner With MongoDB Vector Search

Pavel Duchovny5 min read • Published Sep 24, 2024 • Updated Sep 24, 2024
IAAtlasPesquisa vetorialPHP
APLICATIVO COMPLETO
Ícone do FacebookÍcone do Twitterícone do linkedin
Avalie esse exemplo de código
star-empty
star-empty
star-empty
star-empty
star-empty
social-githubVer código
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

Características principais

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.

Como funciona

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.

Começar

To get started with the Tour Planner, you need a few prerequisites:
  • PHP 8.1+
  • MongoDB extension and prerequisites
  • Composer
  • Node.js e npm
  • MongoDB Atlas cluster
  • Abrir chave de API AI
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.

Conclusão

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.
Principais comentários nos fóruns
Ainda não há comentários sobre este artigo.
Iniciar a conversa

Ícone do FacebookÍcone do Twitterícone do linkedin
Avalie esse exemplo de código
star-empty
star-empty
star-empty
star-empty
star-empty
Relacionado
Início rápido

Pipelines de agregação complexos com Baunilha PHP e MongoDB


Sep 05, 2024 | 10 min read
Notícias e Anúncios

Extensão PHP do MongoDB 1.13.0 – Lançamento


May 24, 2022 | 1 min read
Início rápido

Criar, ler, atualizar e excluir documentos MongoDB com PHP


Sep 11, 2024 | 8 min read
Notícias e Anúncios

Laravel MongoDB 5.0: Lançamento principal com novos recursos interessantes!


Sep 13, 2024 | 1 min read
Tecnologias Utilizadas
Linguagens
Tecnologias
Sumário