Building an Intelligent Recommendation System: Leveraging Node.js, PGVector, and Google Gemini for Personalized Content Discovery
This project provides a service to embed text using Google's Generative AI and store the embeddings in a PostgreSQL database. It also includes functionality to find similar embeddings and recommend content based on user preferences.
- Node.js
- PostgreSQL
- Google Generative AI API Key
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Install dependencies:
npm install
-
Environment Variables: Create a
.env
file in the root directory and add the following:API_KEY=your_google_generative_ai_api_key DATABASE_URL=your_postgresql_database_url ACCESS_TOKEN_SECRET=your_jwt_secret
-
Setup the database:
npx ts-node src/setupDatabase.ts
-
Start the server:
npx ts-node src/index.ts
-
The server will run on
http://localhost:9000
.
- URL:
/user
- Method:
POST
- Body:
{ "name": "username", "password": "userpassword", "preferences": { /* user preferences */ } }
- Response:
{ "userId": "generated_user_id", "name": "username", "preferences": { /* user preferences */ } }
- URL:
/login
- Method:
POST
- Body:
{ "username": "username", "password": "userpassword" }
- Response:
{ "accessToken": "jwt_access_token" }
- URL:
/embed
- Method:
POST
- Headers:
{ "Authorization": "Bearer jwt_access_token" }
- Body:
{ "text": "Your text to embed" }
- Response:
{ "userId": "user_id", "text": "Your text to embed", "embedding": [/* embedding vector */] }
- URL:
/similarity
- Method:
POST
- Headers:
{ "Authorization": "Bearer jwt_access_token" }
- Body:
{ "text": "Your text to find similarity" }
- Response:
[ { "text": "Similar text", "vector": [/* embedding vector */], "distance": 0.123 }, // more results ]
- URL:
/recommend
- Method:
POST
- Headers:
{ "Authorization": "Bearer jwt_access_token" }
- Body:
{ "text": "Your text to get recommendations" }
- Response:
[ { "text": "Recommended text", "similarity": 0.877 }, // more recommendations ]
Postman Documentation Here
This project is licensed under the MIT License.