{"id":18398560,"url":"https://github.com/mongodb-developer/laravel-openai-vector-search","last_synced_at":"2026-02-09T02:32:41.255Z","repository":{"id":260329386,"uuid":"836172673","full_name":"mongodb-developer/laravel-openai-vector-search","owner":"mongodb-developer","description":"Laravel Tour Planner with Open AI and MongoDB Vector Search","archived":false,"fork":false,"pushed_at":"2024-09-24T15:40:46.000Z","size":762,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-01T16:42:25.943Z","etag":null,"topics":["database","generative-ai","laravel","mongodb","openai"],"latest_commit_sha":null,"homepage":"https://www.mongodb.com/developer/code-examples/php/laravel-openai-mongodb-vectorsearch","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mongodb-developer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-31T09:48:46.000Z","updated_at":"2024-12-16T02:52:54.000Z","dependencies_parsed_at":"2024-10-30T18:53:29.714Z","dependency_job_id":null,"html_url":"https://github.com/mongodb-developer/laravel-openai-vector-search","commit_stats":null,"previous_names":["mongodb-developer/laravel-openai-vector-search"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mongodb-developer/laravel-openai-vector-search","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Flaravel-openai-vector-search","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Flaravel-openai-vector-search/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Flaravel-openai-vector-search/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Flaravel-openai-vector-search/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mongodb-developer","download_url":"https://codeload.github.com/mongodb-developer/laravel-openai-vector-search/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Flaravel-openai-vector-search/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269687961,"owners_count":24459395,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","generative-ai","laravel","mongodb","openai"],"created_at":"2024-11-06T02:22:47.177Z","updated_at":"2026-02-09T02:32:41.221Z","avatar_url":"https://github.com/mongodb-developer.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003ca href=\"https://www.mongodb.com/developer/code-examples/php/laravel-openai-mongodb-vectorsearch\" target=\"_blank\"\u003e\u003cimg src=\"https://www.mongodb.com/developer/_next/image/?url=https%3A%2F%2Fimages.contentstack.io%2Fv3%2Fassets%2Fblt39790b633ee0d5a7%2Fbltc8c2f0bc52b11db2%2F65f99d358330b31ad002faea%2FLaravel_DevCenter.png\u0026w=3840\u0026q=75\" width=\"400\" alt=\"Laravel Logo\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## About Laravel\n\nLaravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:\n\n## Learning Laravel\n\nLaravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.\n\nTo leverage MongoDB with Laravel see the following [resources](https://www.mongodb.com/resources/products/compatibilities/mongodb-laravel-integration)\n\n## Tour Planner with MongoDB Vector Search\n\nThis project demonstrates the use of MongoDB Vector Search in a Laravel backend with a Vue.js frontend to create an intelligent tour planning application. It showcases how to leverage vector search capabilities for enhanced search and recommendation features in travel applications. See the article [Introducing the Tour Planner With MongoDB Vector Search](https://www.mongodb.com/developer/code-examples/php/laravel-openai-mongodb-vectorsearch/)\n\n### Project Structure\n\n- `/tour-planner`: Laravel backend\n- `/tour-planner/frontend/tour-planner-frontend`: Vue.js frontend\n\n\n### Features\n\n- City search with vector-based similarity\n- Points of interest recommendation\n- Intelligent trip planning using OpenAI integration\n\n## Vector Search and Laravel sdk\nThe points of interest controller search cities by embeddings generated on city - attraction - desc concat, and gets the searched term as $search\n```php\n$embedding = $this-\u003egenerateEmbedding($search);\n    \n    // Use Atlas Search to search for points of interest within a city\n    $points = DB::collection('points_of_interest')\n    -\u003eraw(\n        function ( $collection) use ($embedding) {\n            \n            return $collection-\u003eaggregate([\n                    [\n                        '$vectorSearch' =\u003e [\n                            'index' =\u003e 'vector_index',\n                            'path' =\u003e 'embedding',\n                            'queryVector' =\u003e $embedding,\n                            'numCandidates' =\u003e 20,\n                            'limit' =\u003e 5\n                            ],\n                        ]\n                    ,\n                    ['$project' =\u003e [\n                        'name' =\u003e 1,\n                        'description' =\u003e 1,\n                        'rating' =\u003e 1,\n                        'location' =\u003e 1,\n                        'score' =\u003e ['$meta' =\u003e 'vectorSearchScore']\n                    ]]\n                ]\n                );\n        },\n    )-\u003etoArray();\n```\n## Retrieval Augmented Generation and Laravel with OpenAI\n\nUsing the relevant context from MongoDB to augment the trip planning JSON response\n\n```php\nprotected function generatePossibleTrip($cities,$context, $days){\n        $result = OpenAI::chat()-\u003ecreate([\n            'model' =\u003e 'gpt-4o-mini',\n            'temperature' =\u003e 0,\n            'response_format' =\u003e ['type' =\u003e 'json_object'],\n            'messages' =\u003e [\n                [\n                    'role' =\u003e 'system',\n                    'content' =\u003e 'You are a travel agent helping a customer plan a trip to a city. If it will be hard to visit that in the number of days Have a one day plan stating the problem. The customer will provide you with points of interest to visit in json.'\n                ],\n                [\n                    'role' =\u003e 'system',\n                    'content' =\u003e 'take this schema, for flights add orig_airport_code and dest_airport_code: \n    \"tripPlan\": {\n      \"destination\": [{\n        \"city\": \"string\",\n        \"country\": \"string\"\n                    }],\n      \"pointsOfInterest\": [\n        {\n          \"name\": \"string\",\n          \"description\": \"string\",\n          \"location\": {\n            \"coordinates\": [number, number]\n          },\n          \"rating\": number\n        }\n      ],\n      // only in relevant direction\n      \"flights\" : [ \"src_airport_code\": \"string\",\n                \"dest_airport_code\": \"string\" \n      ],\n      \"itinerary\": [\n        {\n          \"day\": number,\n          \"destination\": \"string\",\n          \"activities\": [\n            {\n              \"time\": \"string\",\n              \"activity\": \"string\",\n              \"duration\": \"string\",\n              // if flight\n               \"src_airport_code\": \"string\",\n                dest_airport_code: \"string\" \n            }\n              ...\n          ]\n\n        }\n          ...\n      ]\n    }\n '\n                ],\n                [\n                    'role' =\u003e 'user',\n                    'content' =\u003e 'For cities: ' . json_encode($cities) . '| Take this POIs: ' . $context . ' and build a plan for the a trip of ' . $days . 'days. '\n                ]\n            ]\n        ]);\n\n        return $result-\u003echoices[0]-\u003emessage-\u003econtent;\n    \n    }\n```\n\n## Prerequisites\n\n- PHP 8.1+\n    - MongoDB Extension and prereqisites.\n- Composer\n- Node.js and npm\n- MongoDB Atlas cluster\n- OpenAI API key\n\n## Backend Setup (Laravel)\n\nNavigate to the cloned directory:\n\n```\ncd laravel-openai-vector-search\n```\nInstall PHP dependencies:\n```\ncomposer install\n```\n\nCopy the `.env.example` file to `.env` and configure your environment variables:\n```\nOPENAI_API_KEY=your_openai_api_key\nDB_URI=your_atlas_uri\n```\n\nGenerate an application key:\n```\nphp artisan key:generate\n```\n\nRun database migrations and seeders (if any):\n```\nphp artisan db:seed\n```\n\nCreate Atlas vector search index on database: `trip_planner` collection: `points_of_interest`:\n\n** Index name : vector_index **\n```\n{\n  \"fields\": [\n    {\n      \"type\": \"vector\",\n      \"path\": \"embedding\",\n      \"numDimensions\": 1536,\n      \"similarity\": \"cosine\"\n    }\n  ]\n}\n```\n\nStart the Laravel development server:\n```\nphp artisan serve\n```\n\n## Frontend Setup (Vue.js)\n\nNavigate to the frontend directory:\n```\ncd frontend/trip-planner-frontend\nnpm install\nnpm run serve\n```\n\nThe application should be visible at http://localhost:8080 .\n\n## Disclaimer\n\n**Not a MongoDB official product. Use at your own risk**\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongodb-developer%2Flaravel-openai-vector-search","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmongodb-developer%2Flaravel-openai-vector-search","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongodb-developer%2Flaravel-openai-vector-search/lists"}