Skip to content

Commit

Permalink
Integration with Voyage (langchain4j#1816)
Browse files Browse the repository at this point in the history
## Issue
Closes langchain4j#1814 and langchain4j#1813 

## Change
1. Integration `EmbeddingModel` and `ScoringModel` with `Voyage`.
2. Add document about `VoyageEmbeddingModel` and `VoyageScoringModel`

Related PR:

1. [Voyage
Example](langchain4j/langchain4j-examples#109)
2. [Voyage Spring
Boot](langchain4j/langchain4j-spring#42)

## General checklist
<!-- Please double-check the following points and mark them like this:
[X] -->
- [x] There are no breaking changes
- [x] I have added unit and integration tests for my change
- [x] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [x] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
<!-- Before adding documentation and example(s) (below), please wait
until the PR is reviewed and approved. -->
- [x] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
- [x] I have added an example in the [examples
repo](https://github.com/langchain4j/langchain4j-examples) (only for
"big" features)
- [x] I have added/updated [Spring Boot
starter(s)](https://github.com/langchain4j/langchain4j-spring) (if
applicable)

## Checklist for adding new model integration
<!-- Please double-check the following points and mark them like this:
[X] -->
- [x] I have added my new module in the
[BOM](https://github.com/langchain4j/langchain4j/blob/main/langchain4j-bom/pom.xml)
  • Loading branch information
Martin7-1 authored Sep 24, 2024
1 parent 9e2ee93 commit 9e63004
Show file tree
Hide file tree
Showing 23 changed files with 1,732 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/docs/integrations/embedding-models/voyage-ai.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
sidebar_position: 4
---

# Voyage AI

## Maven Dependency

```xml
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-voyage-ai</artifactId>
<version>0.35.0</version>
</dependency>
```

## APIs

- `VoyageAiEmbeddingModel`


## Examples

- [VoyageAiEmbeddingModelIT](https://github.com/langchain4j/langchain4j/blob/main/langchain4j-voyage-ai/src/test/java/dev/langchain4j/model/voyageai/VoyageAiEmbeddingModelIT.java)
- [VoyageAiEmbeddingModelExample](https://github.com/langchain4j/langchain4j-examples/blob/main/voyage-ai-examples/src/main/java/VoyageAiEmbeddingModelExample.java)
25 changes: 25 additions & 0 deletions docs/docs/integrations/scoring-reranking-models/3-voyage-ai.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
sidebar_position: 2
---

# Voyage AI

## Maven Dependency

```xml
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-voyage-ai</artifactId>
<version>0.35.0</version>
</dependency>
```


## Voyage AI Models

- `VoyageAiScoringModel`


## Examples
- [Advanced RAG with re-ranking](https://github.com/langchain4j/langchain4j-examples/blob/main/rag-examples/src/main/java/_3_advanced/_03_Advanced_RAG_with_ReRanking_Example.java)
- [VoyageAiScoringModelExample](https://github.com/langchain4j/langchain4j-examples/blob/main/voyage-ai-examples/src/main/java/VoyageAiScoringModelExample.java)
6 changes: 6 additions & 0 deletions langchain4j-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-voyage-ai</artifactId>
<version>${project.version}</version>
</dependency>

<!-- embedding stores -->

<dependency>
Expand Down
113 changes: 113 additions & 0 deletions langchain4j-voyage-ai/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-parent</artifactId>
<version>0.35.0-SNAPSHOT</version>
<relativePath>../langchain4j-parent/pom.xml</relativePath>
</parent>

<artifactId>langchain4j-voyage-ai</artifactId>
<name>LangChain4j :: Integration :: Voyage AI</name>

<dependencies>
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-core</artifactId>
</dependency>

<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
</dependency>

<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-jackson</artifactId>
</dependency>

<!-- DEPENDENCY CONFLICT RESOLUTION FOR OKHTTP (START) -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>

<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
<!-- DEPENDENCY CONFLICT RESOLUTION FOR OKHTTP (END) -->

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.tinylog</groupId>
<artifactId>tinylog-impl</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.tinylog</groupId>
<artifactId>slf4j-tinylog</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<id>enforce</id>
<configuration>
<rules>
<dependencyConvergence/>
</rules>
</configuration>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package dev.langchain4j.model.voyageai;

import java.util.List;

class EmbeddingRequest {

private List<String> input;
private String model;
private String inputType;
private Boolean truncation;
private String encodingFormat;

EmbeddingRequest() {
}

EmbeddingRequest(List<String> input, String model, String inputType, Boolean truncation, String encodingFormat) {
this.input = input;
this.model = model;
this.inputType = inputType;
this.truncation = truncation;
this.encodingFormat = encodingFormat;
}

public List<String> getInput() {
return input;
}

public String getModel() {
return model;
}

public String getInputType() {
return inputType;
}

public Boolean getTruncation() {
return truncation;
}

public String getEncodingFormat() {
return encodingFormat;
}

static Builder builder() {
return new Builder();
}

static class Builder {

private List<String> input;
private String model;
private String inputType;
private Boolean truncation;
private String encodingFormat;

Builder input(List<String> input) {
this.input = input;
return this;
}

Builder model(String model) {
this.model = model;
return this;
}

Builder inputType(String inputType) {
this.inputType = inputType;
return this;
}

Builder truncation(Boolean truncation) {
this.truncation = truncation;
return this;
}

Builder encodingFormat(String encodingFormat) {
this.encodingFormat = encodingFormat;
return this;
}

EmbeddingRequest build() {
return new EmbeddingRequest(input, model, inputType, truncation, encodingFormat);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package dev.langchain4j.model.voyageai;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import java.util.List;

class EmbeddingResponse {

private String object;
@JsonDeserialize(using = VoyageAiEmbeddingDeserializer.class)
private List<EmbeddingData> data;
private String model;
private TokenUsage usage;

public String getObject() {
return object;
}

public List<EmbeddingData> getData() {
return data;
}

public String getModel() {
return model;
}

public TokenUsage getUsage() {
return usage;
}

static class EmbeddingData {

private String object;
private List<Float> embedding;
private Integer index;

EmbeddingData() {
}

EmbeddingData(String object, List<Float> embedding, Integer index) {
this.object = object;
this.embedding = embedding;
this.index = index;
}

public String getObject() {
return object;
}

public List<Float> getEmbedding() {
return embedding;
}

public Integer getIndex() {
return index;
}
}
}
Loading

0 comments on commit 9e63004

Please sign in to comment.