This project can be used as a starting point to create your own Vaadin application with Spring Boot. It contains all the necessary configuration and some placeholder files to get you started.
To connect this demo applicaiton to your Astra DB vector store you should add a application.yaml file to your project. You shoudl place the file in /config folder. This is a sample yaml file showing what paramaters you need to change to connect to your personal Astra DB. This demo also requires OPEN AI license key which you can define in the same yaml file.
# Open AI license key
openai:
apikey: <YOUR OPEN AI KEY>
# Astra DB Connection properties
astra:
# Allow usage of devops and Stargate apis
api:
endpoint: <API_ENDPOINT>
application-token: <ASTRA_TOKEN>
database-id: <ASTRA_DB_ID>
database-region: <ASTRA_REGION>
default-keyspace: default_keyspace
cross-region-failback: false
grpc:
enabled: true
# Connectivity to Cassandra
cql:
enabled: true
download-scb:
enabled: true
Various Langchain4J features are configured in AiServiceConfigurator class, located in package com.samistax.application.ai package.
The project is a standard Maven project. To run it from the command line,
type mvnw
(Windows), or ./mvnw
(Mac & Linux), then open
http://localhost:8080 in your browser.
You can also import the project to your IDE of choice as you would with any Maven project. Read more on how to import Vaadin projects to different IDEs (Eclipse, IntelliJ IDEA, NetBeans, and VS Code).
To create a production build, call mvnw clean package -Pproduction
(Windows),
or ./mvnw clean package -Pproduction
(Mac & Linux).
This will build a JAR file with all the dependencies and front-end resources,
ready to be deployed. The file can be found in the target
folder after the build completes.
Once the JAR file is built, you can run it using
java -jar target/my-assistant-1.0-SNAPSHOT.jar
When application is started the method loadSampleProductData() in Application.java checks if the products collection exist or not. If it does not then it reads the product information from footwear_sampledata.csv resource files and stores product properties to AStra DB. It also uses embeds the description of the product using Langchain4J AllMiniLmL6V2EmbeddingModel().
MainLayout.java
insrc/main/java
contains the navigation setup (i.e., the side/top bar and the main menu). This setup uses App Layout.views
package insrc/main/java
contains the server-side Java views of your application.views
folder infrontend/
contains the client-side JavaScript views of your application.themes
folder infrontend/
contains the custom CSS styles.
- Read the documentation at vaadin.com/docs.
- Follow the tutorial at vaadin.com/docs/latest/tutorial/overview.
- Create new projects at start.vaadin.com.
- Search UI components and their usage examples at vaadin.com/docs/latest/components.
- View use case applications that demonstrate Vaadin capabilities at vaadin.com/examples-and-demos.
- Build any UI without custom CSS by discovering Vaadin's set of CSS utility classes.
- Find a collection of solutions to common use cases at cookbook.vaadin.com.
- Find add-ons at vaadin.com/directory.
- Ask questions on Stack Overflow or join our Discord channel.
- Report issues, create pull requests in GitHub.
To build the Dockerized version of the project, run
mvn clean package -Pproduction
docker build . -t my-assistant:latest
Once the Docker image is correctly built, you can test it locally using
docker run -p 8080:8080 my-assistant:latest
We assume here that you have the Kubernetes cluster from Docker Desktop running (can be enabled in the settings).
First build the Docker image for your application. You then need to make the Docker image available to you cluster. With Docker Desktop Kubernetes, this happens automatically. With Minikube, you can run eval $(minikube docker-env)
and then build the image to make it available. For other clusters, you need to publish to a Docker repository or check the documentation for the cluster.
The included kubernetes.yaml
sets up a deployment with 2 pods (server instances) and a load balancer service. You can deploy the application on a Kubernetes cluster using
kubectl apply -f kubernetes.yaml
If everything works, you can access your application by opening http://localhost:8000/.
If you have something else running on port 8000, you need to change the load balancer port in kubernetes.yaml
.
Tip: If you want to understand which pod your requests go to, you can add the value of VaadinServletRequest.getCurrent().getLocalAddr()
somewhere in your UI.
If something is not working, you can try one of the following commands to see what is deployed and their status.
kubectl get pods
kubectl get services
kubectl get deployments
If the pods say Container image "my-assistant:latest" is not present with pull policy of Never
then you have not built your application using Docker or there is a mismatch in the name. Use docker images ls
to see which images are available.
If you need even more information, you can run
kubectl cluster-info dump
that will probably give you too much information but might reveal the cause of a problem.
If you want to remove your whole deployment and start over, run
kubectl delete -f kubernetes.yaml