|
| 1 | +# Project Title |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This project serves as an example of how to leverage the Spring AI framework to build applications that utilize generative AI capabilities, specifically focusing on vector embeddings and similarity search. |
| 6 | + |
| 7 | +**Key Features & Technologies:** |
| 8 | + |
| 9 | +* **Spring AI:** Utilizes the Spring AI library to simplify the integration of AI functionalities into a Spring Boot application. |
| 10 | +* **Google Cloud Vertex AI Embeddings:** Demonstrates how to generate text embeddings using Google Cloud's Vertex AI PaLM 2 embedding models. These embeddings convert textual data into numerical vectors, capturing semantic meaning. |
| 11 | +* **MariaDB as a Vector Database:** Shows how MariaDB, with its vector storage and search capabilities (e.g., using its `VECTOR` data type and functions like `VECTOR_COSINE_DISTANCE`), can be used to store and perform similarity searches on the generated Vertex AI embeddings. |
| 12 | +* **Vector Search/Similarity Search:** The core functionality likely involves ingesting data, generating embeddings for it, storing these embeddings in MariaDB, and then performing queries to find items semantically similar to a given input query. |
| 13 | + |
| 14 | +**Purpose:** |
| 15 | + |
| 16 | +The primary goal of this example is to provide developers with a practical, hands-on demonstration of: |
| 17 | +1. Generating high-quality text embeddings with Vertex AI. |
| 18 | +2. Storing these vector embeddings efficiently in MariaDB. |
| 19 | +3. Performing semantic similarity searches against the stored vectors using Spring AI abstractions. |
| 20 | +4. Integrating these components within a standard Spring Boot application. |
| 21 | + |
| 22 | +## Prerequisites |
| 23 | + |
| 24 | +Before you begin, ensure you have the following dependencies and prerequisites met: |
| 25 | + |
| 26 | +* You have installed [Google Cloud SDK](https://cloud.google.com/sdk/docs/install) (which includes `gcloud`). |
| 27 | +* You have a Google Cloud Project. |
| 28 | +* You have appropriate permissions to authenticate and access resources in your Google Cloud Project. |
| 29 | +* [Optional: Add any other project-specific prerequisites, e.g., Node.js, Python, Docker, etc.] |
| 30 | + |
| 31 | +## Setup |
| 32 | + |
| 33 | +Follow these steps to get your development environment set up: |
| 34 | + |
| 35 | +### 1. Clone the Repository (if applicable) |
| 36 | + |
| 37 | +```bash |
| 38 | +git clone <your-repository-url> |
| 39 | +cd <your-project-directory> |
| 40 | +``` |
| 41 | + |
| 42 | +### 2. Set Up Environment Variables |
| 43 | + |
| 44 | +This project requires certain environment variables to be set. The most common one is `PROJECT_ID`. |
| 45 | + |
| 46 | +**Option A: Using a `.env` file (Recommended for local development)** |
| 47 | + |
| 48 | +Create a file named `.env` in the root of your project directory. Add your environment variables there: |
| 49 | + |
| 50 | +```env |
| 51 | +# .env |
| 52 | +PROJECT_ID="your-gcp-project-id" |
| 53 | +# Add other environment variables as needed |
| 54 | +# ANOTHER_VAR="some-value" |
| 55 | +``` |
| 56 | + |
| 57 | +**Important:** Add `.env` to your `.gitignore` file to prevent committing sensitive information. |
| 58 | + |
| 59 | +```gitignore |
| 60 | +# .gitignore |
| 61 | +.env |
| 62 | +``` |
| 63 | + |
| 64 | +**Option B: Exporting directly in your shell** |
| 65 | + |
| 66 | +You can set environment variables directly in your terminal session. These will be lost when the session ends. |
| 67 | + |
| 68 | +```bash |
| 69 | +export PROJECT_ID="your-gcp-project-id" |
| 70 | +# export ANOTHER_VAR="some-value" |
| 71 | +``` |
| 72 | + |
| 73 | +For persistent shell-specific environment variables, add these export commands to your shell's configuration file (e.g., `~/.bashrc`, `~/.zshrc`). |
| 74 | + |
| 75 | +### 3. Configure Google Cloud Application Default Credentials (ADC) |
| 76 | + |
| 77 | +Application Default Credentials (ADC) provide a way for your application to authenticate to Google Cloud services. |
| 78 | + |
| 79 | +1. **Log in to gcloud:** |
| 80 | + If you haven't already, authenticate `gcloud` with your Google Cloud account: |
| 81 | + ```bash |
| 82 | + gcloud auth login |
| 83 | + ``` |
| 84 | + Follow the on-screen instructions to authorize `gcloud`. |
| 85 | + |
| 86 | +2. **Set up Application Default Credentials:** |
| 87 | + This command will store your user credentials in a well-known location on your local machine, which Google Cloud client libraries can automatically find. |
| 88 | + ```bash |
| 89 | + gcloud auth application-default login |
| 90 | + ``` |
| 91 | + This will also open a browser window for you to authenticate. |
| 92 | + |
| 93 | + Your application will now be able to use these credentials to authenticate to Google Cloud services when running locally, provided the authenticated user has the necessary IAM permissions for the resources your application needs to access. |
| 94 | + |
| 95 | +### 4. [Optional: Add other setup steps] |
| 96 | + |
| 97 | +* Install dependencies: `npm install`, `pip install -r requirements.txt`, etc. |
| 98 | +* Database setup instructions. |
| 99 | +* ... |
| 100 | + |
| 101 | +## Running the Application |
| 102 | + |
| 103 | +[Instructions on how to run your application, e.g., `npm start`, `python app.py`] |
| 104 | + |
| 105 | +## Debugging |
| 106 | + |
| 107 | +If you are using VS Code, ensure your `.vscode/launch.json` is configured to pass environment variables. For example: |
| 108 | + |
| 109 | +```json |
| 110 | +{ |
| 111 | + "version": "0.2.0", |
| 112 | + "configurations": [ |
| 113 | + { |
| 114 | + "name": "Launch Program", |
| 115 | + "type": "node", // or "python", etc. |
| 116 | + "request": "launch", |
| 117 | + "program": "${workspaceFolder}/your-main-file.js", |
| 118 | + "env": { |
| 119 | + "PROJECT_ID": "your-gcp-project-id" |
| 120 | + // You can also use "${env:PROJECT_ID}" if it's set in your shell |
| 121 | + } |
| 122 | + } |
| 123 | + ] |
| 124 | +} |
| 125 | +``` |
| 126 | +
|
| 127 | +Replace `"your-gcp-project-id"` with your actual Project ID or use environment variable substitution if you prefer. |
| 128 | +
|
| 129 | +--- |
| 130 | +
|
| 131 | +Remember to replace placeholders like `<your-repository-url>`, `<your-project-directory>`, `"your-gcp-project-id"`, and any other project-specific details with your actual information. |
| 132 | +
|
| 133 | +This README provides a good starting point. You can expand it further with more specific details about your project, such as deployment instructions, contribution guidelines, or licensing information. |
0 commit comments