Skip to content

Guide to Building an Intelligent Recommendation System Using Node.js, PGVector, and Google Gemini for Personalized Content Discovery

Notifications You must be signed in to change notification settings

johnexzy/Smart-recommender

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Prerequisites

  • Node.js
  • PostgreSQL
  • Google Generative AI API Key

Setup

  1. Clone the repository:

    git clone <repository-url>
    cd <repository-directory>
  2. Install dependencies:

    npm install
  3. 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
  4. Setup the database:

    npx ts-node src/setupDatabase.ts

Running the Service

  1. Start the server:

    npx ts-node src/index.ts
  2. The server will run on http://localhost:9000.

API Endpoints

User Management

Create User

  • URL: /user
  • Method: POST
  • Body:
    {
        "name": "username",
        "password": "userpassword",
        "preferences": { /* user preferences */ }
    }
  • Response:
    {
        "userId": "generated_user_id",
        "name": "username",
        "preferences": { /* user preferences */ }
    }

User Login

  • URL: /login
  • Method: POST
  • Body:
    {
        "username": "username",
        "password": "userpassword"
    }
  • Response:
    {
        "accessToken": "jwt_access_token"
    }

Embedding and Similarity

Embed Text

  • 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 */]
    }

Find Similar Embeddings

  • 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
    ]

Recommendations

Recommend Similar Texts

  • 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

License

This project is licensed under the MIT License.

About

Guide to Building an Intelligent Recommendation System Using Node.js, PGVector, and Google Gemini for Personalized Content Discovery

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published