Skip to content

Commit 771ac05

Browse files
committed
feature: adding vector db example using vertex ai
Signed-off-by: [email protected] <[email protected]>
1 parent bede0b6 commit 771ac05

22 files changed

+1083
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/mvnw text eol=lf
2+
*.cmd text eol=crlf
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**/target/
5+
!**/src/test/**/target/
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
!**/src/main/**/build/
30+
!**/src/test/**/build/
31+
32+
### VS Code ###
33+
.vscode/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
wrapperVersion=3.3.2
18+
distributionType=only-script
19+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#GET http://localhost:8080/scrapeAll HTTP/1.1
2+
#content-type: application/json
3+
4+
#{
5+
# "text": "What does my insurance policy cover?",
6+
# "rag": true
7+
#}
8+
9+
GET http://localhost:8080/embeddingsMessage?message="How can i submit expense report of my last trip?" HTTP/1.1

0 commit comments

Comments
 (0)