Skip to content

JohnKennedyOSS/alloyDB-Omni-vector-search

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AlloyDB Semantic Product Search

A demonstration of semantic search capabilities using local embeddings with Google's Gemini models and Aiven for AlloyDB Omni.

Overview

This application demonstrates how to implement semantic search for product data stored in AlloyDB. Instead of relying on AlloyDB's built-in integration with Google's Vertex AI, this application generates embeddings locally using the Gemini API and stores them in the database.

Features

  • Semantic Product Search: Search for products using natural language queries
  • Add Products: Add new products to the database with automatically generated embeddings
  • Update Embeddings: Generate or update embeddings for existing products

Setup

Prerequisites

  • Python 3.8+
  • An AlloyDB Omni instance (e.g., through Aiven)
  • A Google API key with access to the Gemini API

Installation

  1. Clone this repository
  2. Install the required packages:
    pip install -r requirements.txt
    

Configuration

  1. Create a .env file in the root directory with the following variables:

    ALLOY_DB_USER=your_db_user
    ALLOY_DB_PASSWORD=your_db_password
    ALLOY_DB_HOST=your_db_host
    ALLOY_DB_PORT=your_db_port
    GEMINI_API_KEY=your_gemini_api_key
    
  2. Create a .streamlit directory and inside it create a secrets.toml file with the following content:

    [connections.postgresql]
    dialect = "postgresql"
    host = "your_db_host"
    port = 12345  # Your DB port
    database = "defaultdb"
    username = "your_db_user"
    password = "your_db_password"

Running the Application

Launch the Streamlit application:

streamlit run modified_search.py

Troubleshooting

If you encounter any issues:

  1. Enable Debug Mode in the sidebar to see detailed error messages
  2. Run the simple_test.py script to verify your database connection:
    python simple_test.py
    
  3. Make sure all environment variables are correctly set

Database Schema

The application expects a product table with the following schema:

CREATE TABLE product (
    id SERIAL PRIMARY KEY,
    title VARCHAR(255) NOT NULL,
    description TEXT,
    price NUMERIC(10, 2),
    images TEXT,
    emb REAL[]
);

Implementation Details

  • Embeddings are generated using Google's Gemini models/embedding-001 model
  • Embeddings are stored in the emb column as arrays of floating-point numbers
  • Similarity is calculated using cosine similarity between the query embedding and product embeddings

Note on Streamlit Version

This application uses st.experimental_connection() which is compatible with Streamlit version 1.27.2. If you have a newer version of Streamlit that supports st.connection(), you may need to update the code accordingly.

About

Demo for Google Next 2025

Resources

Stars

Watchers

Forks

Packages

No packages published