{"id":21042709,"url":"https://github.com/yugabytedb-samples/openai-pgvector-lodging-service","last_synced_at":"2025-05-15T17:30:59.416Z","repository":{"id":196903680,"uuid":"694729570","full_name":"YugabyteDB-Samples/openai-pgvector-lodging-service","owner":"YugabyteDB-Samples","description":"A lodging recommendation service for properties in San Francisco, powered by OpenAI and the PostgreSQL pgvector extension.","archived":false,"fork":false,"pushed_at":"2024-01-23T03:18:08.000Z","size":26928,"stargazers_count":13,"open_issues_count":0,"forks_count":9,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-01-23T04:30:28.035Z","etag":null,"topics":["java","nodejs","openai","openai-api","pgvector","postgresql","react","yugabytedb"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YugabyteDB-Samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2023-09-21T15:16:47.000Z","updated_at":"2024-04-15T15:55:32.395Z","dependencies_parsed_at":null,"dependency_job_id":"f34a0ef9-e285-48c8-9dce-89348d2aebbc","html_url":"https://github.com/YugabyteDB-Samples/openai-pgvector-lodging-service","commit_stats":null,"previous_names":["yugabytedb-samples/openai-pgvector-lodging-service"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fopenai-pgvector-lodging-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fopenai-pgvector-lodging-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fopenai-pgvector-lodging-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Fopenai-pgvector-lodging-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YugabyteDB-Samples","download_url":"https://codeload.github.com/YugabyteDB-Samples/openai-pgvector-lodging-service/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254388052,"owners_count":22062976,"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","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":["java","nodejs","openai","openai-api","pgvector","postgresql","react","yugabytedb"],"created_at":"2024-11-19T14:08:44.613Z","updated_at":"2025-05-15T17:30:59.160Z","avatar_url":"https://github.com/YugabyteDB-Samples.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lodging Recommendation Service With OpenAI and PostgreSQL pgvector extension\n\nThis sample app shows how to build generative AI apps using OpenAI API and the PostgreSQL pgvector extension.\n\nThe app provides recommendations for various lodging options for travelers heading to San Francisco. It operates in two distinct modes:\n\n![openai_lodging](https://github.com/YugabyteDB-Samples/openai-pgvector-lodging-service/assets/1537233/d070dfe1-50f9-4191-ae43-c80ba61deb2a)\n\n* *OpenAI Chat Mode*: In this mode, the backend leverages the OpenAI Chat Completion API and the GPT-4 model to generate lodging recommendations based on the user's input.\n* *Postgres Embeddings Mode*: Initially, the backend employs the OpenAI Embeddings API to generate an embedding from the user's input. Subsequently, the server utilizes the PostgreSQL pgvector extension to perform a vector search among the sample Airbnb properties stored in the database. You can use PostgreSQL or YugabyteDB.\n\n## Prerequisites\n\n* [OpenAI API key](https://platform.openai.com)\n* [git-lfs](https://github.com/git-lfs/git-lfs) - Git needs this extension to download a large data set file used by this sample app.\n\n## Start the Database\n\nThe pgvector extension is supported by both PostgresSQL and YugabyteDB. Follow the steps below for starting a database instance using a docker image with pgvector. \n\n(Note, the sample data set includes embeddings generated with the `text-embedding-ada-002` model. If you need to use a different model, preload the data following the instructions below and then use the `backend/node/embeddings_generator.js` to regenerate the embeddings using your model).\n\n### YugabyteDB \n\n1. Launch a 3-node YugabyteDB cluster of version 2.19.2.0 or later:\n    ```shell\n    mkdir ~/yugabyte_volume\n\n    docker network create custom-network\n\n    docker run -d --name yugabytedb-node1 --net custom-network \\\n        -p 15433:15433 -p 7001:7000 -p 9001:9000 -p 5433:5433 \\\n        -v ~/yugabyte_volume/node1:/home/yugabyte/yb_data --restart unless-stopped \\\n        yugabytedb/yugabyte:latest \\\n        bin/yugabyted start \\\n        --base_dir=/home/yugabyte/yb_data --daemon=false\n    \n    docker run -d --name yugabytedb-node2 --net custom-network \\\n        -p 15434:15433 -p 7002:7000 -p 9002:9000 -p 5434:5433 \\\n        -v ~/yugabyte_volume/node2:/home/yugabyte/yb_data --restart unless-stopped \\\n        yugabytedb/yugabyte:latest \\\n        bin/yugabyted start --join=yugabytedb-node1 \\\n        --base_dir=/home/yugabyte/yb_data --daemon=false\n        \n    docker run -d --name yugabytedb-node3 --net custom-network \\\n        -p 15435:15433 -p 7003:7000 -p 9003:9000 -p 5435:5433 \\\n        -v ~/yugabyte_volume/node3:/home/yugabyte/yb_data --restart unless-stopped \\\n        yugabytedb/yugabyte:latest \\\n        bin/yugabyted start --join=yugabytedb-node1 \\\n        --base_dir=/home/yugabyte/yb_data --daemon=false\n    ```\n2. Copy the Airbnb schema and data to the first node's container:\n    ```shell\n    docker cp {project_dir}/sql/airbnb_listings.sql yugabytedb-node1:/home\n    docker cp {project_dir}/sql/airbnb_listings_with_embeddings.csv yugabytedb-node1:/home\n    ```\n    *Make sure you have the git-lfs installed at the time you clone the project. The `airbnb_listings_with_embeddings.csv` file is stored in the Git Large File Storage.*\n\n\n3. Load the dataset to the cluster (note, it can take a minute to load the data):\n    ```shell\n    docker exec -it yugabytedb-node1 bin/ysqlsh -h yugabytedb-node1 -c '\\i /home/airbnb_listings.sql'\n    docker exec -it yugabytedb-node1 bin/ysqlsh -h yugabytedb-node1 \\\n        -c \"\\copy airbnb_listing from /home/airbnb_listings_with_embeddings.csv with DELIMITER '^' CSV\"\n    ```\n\n### PostgreSQL\n\n1. Launch a Postgres instance using the docker image with pgvector:\n    ```shell\n    mkdir ~/postgres-volume/\n\n    docker run --name postgres \\\n        -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password \\\n        -p 5432:5432 \\\n        -v ~/postgres-volume/:/var/lib/postgresql/data -d ankane/pgvector:latest\n    ```\n\n2. Copy the Airbnb schema and data to the container:\n    ```shell\n    docker cp {project_dir}/sql/airbnb_listings.sql postgres:/home\n    docker cp {project_dir}/sql/airbnb_listings_with_embeddings.csv postgres:/home\n    ```\n    *Make sure you have the git-lfs installed at the time you clone the project. The `airbnb_listings_with_embeddings.csv` file is stored in the Git Large File Storage.*\n\n\n4. Load the dataset to Postgres (note, it can take a minute to load the data):\n    ```shell\n    docker exec -it postgres psql -U postgres -c '\\i /home/airbnb_listings.sql'\n    docker exec -it postgres psql -U postgres \\\n        -c \"\\copy airbnb_listing from /home/airbnb_listings_with_embeddings.csv with DELIMITER '^' CSV\"\n    ```\n\n## Starting the Application\n\n1. Start one of the available backend implementations:\n    * [Java backend](backend/java/README.md)\n    * [Node.js backend](backend/node/README.md)\n2. Start the React frontend:\n    ```shell\n    cd {project_dir}/frontend\n    npm i\n    npm start\n    ```\n3. Access the application's user interface at:\n    http://localhost:3000\n\nEnjoy exploring the app and toggling between the two modes: *OpenAI Chat* and *Postgres Embeddings*. The latter is significantly faster.\n\n**Note**: Ensure you request recommendations specifically for lodging in San Francisco, as this is the AI's primary focus.\n\n![app_screenshot](https://github.com/YugabyteDB-Samples/openai-pgvector-lodging-service/assets/1537233/58c573d6-7632-4cf4-96e1-066d3b0c6314)\n\nHere are some sample prompts to get you started:\n```\nWe're traveling to San Francisco from October 21st through 28th. We need a hotel with parking.\n\nI'm looking for an apartment near the Golden Gate Bridge with a Bay view.\n\nI'd like a hotel near Fisherman's Wharf with a Bay view.\n\nAn apartment close to the Salesforce Tower, within walking distance of Blue Bottle Coffee.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyugabytedb-samples%2Fopenai-pgvector-lodging-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyugabytedb-samples%2Fopenai-pgvector-lodging-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyugabytedb-samples%2Fopenai-pgvector-lodging-service/lists"}