Git Product home page Git Product logo

llm-integration's Introduction

Overview

This is a spring starter, that enables semantic (or "human language") search, backed by OpenAI Platform, for spring application, by couple declaration / configuration customization lines

How to build

  • As a Vector DB Apache Lucene (https://github.com/apache/lucene) is used, which has support for similarity search. You need to patch it as the maximum supported vector dimension (1024) at least in latest stable version is not enough for ChatGPT. I applied to the version 9.7.0 the following patch and built according Lucene Core documentation as artifact 'org.apache.lucene:lucene-core:9.7.0+knn2048'
Index: lucene/core/src/java/org/apache/lucene/index/FloatVectorValues.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lucene/core/src/java/org/apache/lucene/index/FloatVectorValues.java b/lucene/core/src/java/org/apache/lucene/index/FloatVectorValues.java
--- a/lucene/core/src/java/org/apache/lucene/index/FloatVectorValues.java	(revision 01e2eb6944b8b9f4a931dfed75dffb3cc56eb341)
+++ b/lucene/core/src/java/org/apache/lucene/index/FloatVectorValues.java	(revision 2c1681a01a8e8039b598d25306fb89cf51574801)
@@ -29,7 +29,7 @@
 public abstract class FloatVectorValues extends DocIdSetIterator {
 
   /** The maximum length of a vector */
-  public static final int MAX_DIMENSIONS = 1024;
+  public static final int MAX_DIMENSIONS = 2048;
 
   /** Sole constructor */
   protected FloatVectorValues() {}

How to enable

  • add dependency 'org.novomax:llm-integration-all-in-one-spring-boot-starter:0.0.1-SNAPSHOT'
  • You need to annotate an entry with @EntityListeners annotation, which refers TextUpdateListener.class and you text-getter with @LlmText
import org.novomax.llm.integration.spring.client.TextUpdateListener;

@Entity
@EntityListeners({TextUpdateListener.class})
public class YouEntity {
    // ...
    @LlmText
    public String getSomeText() {
    }
}
  • Add org.novomax.llm.integration.spring.LlmConfig for Spring scan, e.g.
@SpringBootApplication(scanBasePackageClasses = {YourApplication.class, LlmConfig.class})
public class YouApp{/*...*/}
  • property org.novomax.llm.integration.spring.openai.api.key should have your API key for openai
  • optional: to have a search form without coding, you should configure mapping of URL Path for an entity with placeholder for ID (corresponding to ID of the JPA Entity)
org:
  novomax:
    llm:
      integration:
        ui:
          searchOneMapping:
            "[yourpackage.YourEntity]": /path/to/view-entity/{0}

How does it work

sequence_update.png sequence_search.png

llm-integration's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.