Skip to main content

Getting started

eLLMental is a library designed for building AI-powered applications written in Java, and it offers production-ready components that can be used right away in your current JVM projects. In this guide, we will showcase how to use the EmbeddingsSpaceComponent to find relevant text based on a query.

Step 1: Add the eLLMental dependencies

You can import the eLLMental library from Maven Central. Below there are some examples of how you can do it.


Incorporate the eLLMental dependencies into your build.gradle file.

repositories {

dependencies {
implementation "com.theagilemonkeys.ellmental:core:0.0.2"
implementation "com.theagilemonkeys.ellmental:embeddingsgeneration:0.0.2"
implementation "com.theagilemonkeys.ellmental:embeddingsstore:0.0.2"
implementation "com.theagilemonkeys.ellmental:embeddingsspace:0.0.2"
// Other dependencies


You can also add the eLLMental dependencies into your pom.xml file.

<!-- ... other configurations ... -->

<!-- Add the eLLMental dependencies -->

<!-- ... other configurations ... -->

Step 2: Initializing the EmbeddingsSpaceComponent

Before initializing the EmbeddingsSpaceComponent, set up the OpenAIEmbeddingsModel and PineconeVectorStore.

Retrieve the required API tokens and configuration parameters following the PineCone quickstart guide and OpenAI API keys guide.

import com.theagilemonkeys.ellmental.embeddingsmodel.openai.OpenAIEmbeddingsModel;
import com.theagilemonkeys.ellmental.vectorstore.pinecone.PineconeVectorStore;

public OpenAIEmbeddingsModel embeddingsModel() {
return new OpenAIEmbeddingsModel("OPEN_AI_API_KEY");

public PineconeVectorStore vectorStore() {

Now, initialize the EmbeddingsSpaceComponent:

import com.theagilemonkeys.ellmental.EmbeddingsSpaceComponent;

public EmbeddingsSpaceComponent initializeEmbeddingsSpace() {
return new EmbeddingsSpaceComponent(embeddingsModel(), vectorStore());

Step 3: Running the example

To run an example, you can write a simple main function:

public class MainApp {

public static void main(String[] args) {
EmbeddingsSpaceComponent embeddingsSpace = initializeEmbeddingsSpace();

// Add some embedding samples to the embeddings space."Hello, eLLMental!");"Hello, world!");"Hi!");"Cats are cute");"Dogs are loyal");
// You can provide Metadata to the `save` call too
Map<String, String> metadata = new HashMap<>();
metadata.put("key", "value");"Hey there!", metadata)

// Search similar embeddings
List<Embedding> results = embeddingsSpace.mostSimilarEmbeddings("Greetings!", 3);
for (Embedding embedding : results) {

Run the main function, and you should see the most similar texts to "Greetings!":

$ ./gradlew run

> Task :run
Hello, eLLMental!
Hello, world!

Notice that the result outputs three entries because we specified the limit to be 3 in the mostSimilarEmbeddings function, but you can change this value to any number you want. Take into account that in the embeddings space, the database will calculate distances with every other embedding, so higher limits may return results that are not strictly similar to the query. Take into account that the list is ranked by similarity, so the first result is the most similar to the query and the latest is the least similar.

eLLMental ❤️ Springboot

If you prefer to use eLLMental from Springboot, you can always use the file to import your environment variables and just modify a little bit the code as seen below:

Importing env variables from



Configuring EmbeddingsSpaceComponent

import com.theagilemonkeys.ellmental.EmbeddingsSpaceComponent;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

public class EllmentalConfiguration{

private String openAiApiKey;

private String pineconeApiKey;

private String pineconeUrl;

private String pineconeNamespace;

private OpenAIEmbeddingsModel embeddingsModel() {
return new OpenAIEmbeddingsModel(openAiApiKey);

private PineconeVectorStore vectorStore() {
return new PineconeVectorStore(pineconeApiKey, pineconeUrl, pineconeNamespace);

// Usable public Bean
public EmbeddingsSpaceComponent embeddingsSpaceComponent() {
return new EmbeddingsSpaceComponent(embeddingsModel(), vectorStore());

Autowiring EmbeddingsSpaceComponent

import com.theagilemonkeys.ellmental.EmbeddingsSpaceComponent;
import org.springframework.beans.factory.annotation.Autowired;

public class SomeServiceClass {
private final EmbeddingsSpaceComponent embeddingsSpaceComponent;

public SomeServiceClass(EmbeddingsSpaceComponent embeddingsSpaceComponent){
this.embeddingsSpaceComponent = embeddingsSpaceComponent;

// ...Here you can use embeddingsSpaceComponent

Next steps

Now that you've learned the basics, you can include eLLMental in your own projects and start experimenting. Try to generate embeddings for a larger corpus of texts like HTML files extracted from a web scraper process, a series of blog posts from your database or a collection of tweets from your Twitter account