diff --git a/spring-ai-chat/README.md b/spring-ai-chat/README.md index decb87799..77894e8b7 100644 --- a/spring-ai-chat/README.md +++ b/spring-ai-chat/README.md @@ -20,11 +20,30 @@ In order to compile the production code: ./mvnw clean compile ``` + + After that it is a good habit to compile the test classes and execute those tests to see if your application is still behaving as you would expect: ```sh ./mvnw verify ``` + +### Using PostgreSQL/pgvector + +If you chose PostgreSQL/pgvector as your vector store, you'll need to run a PostgresSQL database instance before running the application. The PostgreSQL database needs to have the "vector" extension available. + +You can use this command to start a PostgreSQL container that includes the "vector" extension: + +```sh +docker run --rm --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=password -d pgvector/pgvector:pg17 +``` + +After that it is a good habit to compile the test classes and execute those tests to see if your application is still behaving as you would expect: + +```sh +./mvnw -Dspring.profiles.active=pgvector verify +``` + ## Start and interact Spring Boot has its own integrated Web Server (Apache Tomcat (https://tomcat.apache.org/)). @@ -35,19 +54,35 @@ Set the `AI_API_KEY` environment variable with the API key to be used by your ap export AI_API_KEY='' ``` -Launch application using default profile: + +### Using embedded simple store + +Launch application using the default profile: ```sh ./mvnw spring-boot:run ``` + +### Using PostgreSQL/pgvector -### Accessing home page +If you chose PostgreSQL/pgvector as your vector store, you'll need to run a PostgresSQL database instance before running the application. The PostgreSQL database needs to have the "vector" extension available. + +You can use this command to start a PostgreSQL container that includes the "vector" extension: + +```sh +docker run --rm --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=password -d pgvector/pgvector:pg17 +``` -You can access the public page at `http://localhost:8080/` by a web browser or using `curl`: +Run the application using the pgvector profile: ```sh -curl -L -H 'Content-Type: application/html' http://localhost:8080/ +./mvnw -Dspring-boot.run.profiles=pgvector spring-boot:run ``` + + +### Accessing home page + +You can access the public page at http://localhost:8080/ via a web browser. You'll be presented with a login page. You may login with either of the following sets of credentials: @@ -103,6 +138,16 @@ You can set an environment variable for the app using this command: tanzu app env set spring-ai-chat AI_API_KEY= ``` + + +### PostgreSQL/pgvector + +If you chose PostgreSQL/pgvector as your vector store, you'll need to create +a PostgresSQL database instance before deploying the application. The PostgreSQL database needs to have the "vector" extension available. + +Instructions TBD. + + ### Scale the number of instances Run this command to scale to 1 instance diff --git a/spring-ai-chat/accelerator.axl b/spring-ai-chat/accelerator.axl index 606bea11c..91aebced3 100644 --- a/spring-ai-chat/accelerator.axl +++ b/spring-ai-chat/accelerator.axl @@ -1,11 +1,14 @@ engine { - applyTo("pom.xml" || "src/main/resources/application.properties") { + applyTo("README.md" || "pom.xml" || "src/main/resources/application.properties") { TextPreprocessor() } - if (#vectorStoreType != 'simple') { - Exclude({"**/SimpleVectorStoreConfig.java"}) + if (#vectorStoreType == 'simple') { + Exclude({"**/schema-pgvector.sql", "**/application-pgvector.properties"}) + } + else { + Exclude({"**/SimpleVectorStoreConfig.java"}) } applyTo("pom.xml") { diff --git a/spring-ai-chat/src/main/resources/application-pgvector.properties b/spring-ai-chat/src/main/resources/application-pgvector.properties new file mode 100644 index 000000000..cbed83cad --- /dev/null +++ b/spring-ai-chat/src/main/resources/application-pgvector.properties @@ -0,0 +1,10 @@ +spring.ai.vectorstore.pgvector.index-type=ivfflat +spring.ai.vectorstore.pgvector.distance-type=euclidean_distance + +spring.datasource.url=jdbc:postgresql://localhost/postgres +spring.datasource.driver-class-name=org.postgresql.Driver +spring.datasource.username=postgres +spring.datasource.password=password +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +spring.sql.init.mode=always +spring.sql.init.platform=pgvector diff --git a/spring-ai-chat/src/main/resources/schema-pgvector.sql b/spring-ai-chat/src/main/resources/schema-pgvector.sql new file mode 100644 index 000000000..3c0d84022 --- /dev/null +++ b/spring-ai-chat/src/main/resources/schema-pgvector.sql @@ -0,0 +1,10 @@ +CREATE EXTENSION IF NOT EXISTS vector; +CREATE EXTENSION IF NOT EXISTS hstore; +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; +CREATE TABLE IF NOT EXISTS vector_store ( + id uuid DEFAULT uuid_generate_v4() PRIMARY KEY, + content text, + metadata json, + embedding vector(1536) +); +CREATE INDEX ON vector_store USING HNSW (embedding vector_cosine_ops);