Skip to content

Commit

Permalink
fix: 修复有关Pinecone向量数据库的一些问题
Browse files Browse the repository at this point in the history
  • Loading branch information
LnYo-Cly committed Sep 26, 2024
1 parent ec8270c commit 76bb59f
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 14 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
+ 轻松使用Tool Calls
+ 支持多个函数同时调用(智谱不支持)
+ 支持stream_options,流式输出直接获取统计token usage
+ 内置向量数据库支持: Pinecone
+ 支持RAG,内置向量数据库支持: Pinecone
+ 使用Tika读取文件
+ Token统计`TikTokensUtil.java`

## 更新日志
+ [2024-09-26] 修复有关Pinecone向量数据库的一些问题。发布0.6.3版本
+ [2024-09-20] 增加对Ollama平台的支持,并修复一些bug。发布0.6.2版本
+ [2024-09-19] 增加错误处理链,统一处理为openai错误类型; 修复部分情况下URL拼接问题,修复拦截器中response重复调用而导致的关闭问题。发布0.5.3版本
+ [2024-09-12] 修复上个问题OpenAi参数导致错误的遗漏,发布0.5.2版本
Expand Down
2 changes: 1 addition & 1 deletion ai4j-spring-boot-stater/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>io.github.lnyo-cly</groupId>
<artifactId>ai4j-spring-boot-stater</artifactId>
<packaging>jar</packaging>
<version>0.6.2</version>
<version>0.6.3</version>

<name>ai4j-spring-boot-stater</name>
<description>为aj4j所提供的spring-stater,便于接入spring项目。关于ai4j: 一款JavaSDK用于快速接入AI大模型应用,整合多平台大模型,如OpenAi、Ollama、智谱Zhipu(ChatGLM)、深度求索DeepSeek、月之暗面Moonshot(Kimi)、腾讯混元Hunyuan、零一万物(01)等等,提供统一的输入输出(对齐OpenAi)消除差异化,优化函数调用(Tool Call),优化RAG调用、支持向量数据库(Pinecone),并且支持JDK1.8,为用户提供快速整合AI的能力。</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private void initZhipuConfig() {
*/
private void initPineconeConfig() {
PineconeConfig pineconeConfig = new PineconeConfig();
pineconeConfig.setUrl(pineconeConfigProperties.getUrl());
pineconeConfig.setHost(pineconeConfigProperties.getHost());
pineconeConfig.setKey(pineconeConfigProperties.getKey());
pineconeConfig.setUpsert(pineconeConfigProperties.getUpsert());
pineconeConfig.setQuery(pineconeConfigProperties.getQuery());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Data
@ConfigurationProperties(prefix = "ai.vector.pinecone")
public class PineconeConfigProperties {
private String url = "https://xxx.svc.xxx.pinecone.io";
private String host = "https://xxx.svc.xxx.pinecone.io";
private String key = "";

private String upsert = "/vectors/upsert";
Expand Down
2 changes: 1 addition & 1 deletion ai4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>io.github.lnyo-cly</groupId>
<artifactId>ai4j</artifactId>
<packaging>jar</packaging>
<version>0.6.2</version>
<version>0.6.3</version>

<name>ai4j</name>
<description>一款JavaSDK用于快速接入AI大模型应用,整合多平台大模型,如OpenAi、Ollama、智谱Zhipu(ChatGLM)、深度求索DeepSeek、月之暗面Moonshot(Kimi)、腾讯混元Hunyuan、零一万物(01)等等,提供统一的输入输出(对齐OpenAi)消除差异化,优化函数调用(Tool Call),优化RAG调用、支持向量数据库(Pinecone),并且支持JDK1.8,为用户提供快速整合AI的能力。</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@NoArgsConstructor
@AllArgsConstructor
public class PineconeConfig {
private String url = "https://xxx.svc.xxx.pinecone.io";
private String host = "https://xxx.svc.xxx.pinecone.io";
private String key = "";

private String upsert = "/vectors/upsert";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.github.lnyocly.ai4j.vector;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

Expand All @@ -10,6 +12,8 @@
* @Date 2024/8/14 18:23
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class VertorDataEntity {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class PineconeQuery {
/**
* 指示响应中是否包含元数据以及id
*/
@Builder.Default
private Boolean includeMetadata = true;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import io.github.lnyocly.ai4j.constant.Constants;
import io.github.lnyocly.ai4j.exception.CommonException;
import io.github.lnyocly.ai4j.service.Configuration;
import io.github.lnyocly.ai4j.utils.ValidateUtil;
import io.github.lnyocly.ai4j.vector.VertorDataEntity;
import io.github.lnyocly.ai4j.vector.pinecone.*;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -37,8 +37,8 @@ public PineconeService(Configuration configuration) {
// 插入Pinecone向量库
public Integer insert(PineconeInsert pineconeInsertReq){
Request request = new Request.Builder()
.url(pineconeConfig.getUrl() + pineconeConfig.getUpsert())
.post(RequestBody.create(JSON.toJSONString(pineconeInsertReq), MediaType.parse(Constants.APPLICATION_JSON)))
.url(ValidateUtil.concatUrl(pineconeConfig.getHost(), pineconeConfig.getUpsert()))
.post(RequestBody.create(MediaType.parse(Constants.APPLICATION_JSON), JSON.toJSONString(pineconeInsertReq)))
.header("accept", Constants.APPLICATION_JSON)
.header("content-type", Constants.APPLICATION_JSON)
.header("Api-Key", pineconeConfig.getKey())
Expand Down Expand Up @@ -76,8 +76,8 @@ public Integer insert(VertorDataEntity vertorDataEntity, String namespace) {
// 从Pinecone向量库中查询相似向量
public PineconeQueryResponse query(PineconeQuery pineconeQueryReq){
Request request = new Request.Builder()
.url(pineconeConfig.getUrl() + pineconeConfig.getQuery())
.post(RequestBody.create(JSON.toJSONString(pineconeQueryReq), MediaType.parse(Constants.APPLICATION_JSON)))
.url(ValidateUtil.concatUrl(pineconeConfig.getHost(), pineconeConfig.getQuery()))
.post(RequestBody.create(MediaType.parse(Constants.APPLICATION_JSON), JSON.toJSONString(pineconeQueryReq)))
.header("accept", Constants.APPLICATION_JSON)
.header("content-type", Constants.APPLICATION_JSON)
.header("Api-Key", pineconeConfig.getKey())
Expand Down Expand Up @@ -106,8 +106,8 @@ public String query(PineconeQuery pineconeQuery, String delimiter){
// 从Pinecone向量库中删除向量
public Boolean delete(PineconeDelete pineconeDeleteReq){
Request request = new Request.Builder()
.url(pineconeConfig.getUrl() + pineconeConfig.getDelete())
.post(RequestBody.create(JSON.toJSONString(pineconeDeleteReq), MediaType.parse(Constants.APPLICATION_JSON)))
.url(ValidateUtil.concatUrl(pineconeConfig.getHost(), pineconeConfig.getDelete()))
.post(RequestBody.create(MediaType.parse(Constants.APPLICATION_JSON), JSON.toJSONString(pineconeDeleteReq)))
.header("accept", Constants.APPLICATION_JSON)
.header("content-type", Constants.APPLICATION_JSON)
.header("Api-Key", pineconeConfig.getKey())
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>io.github.lnyo-cly</groupId>
<artifactId>ai4j-sdk</artifactId>

<version>0.6.2</version>
<version>0.6.3</version>

<packaging>pom</packaging>

Expand Down

0 comments on commit 76bb59f

Please sign in to comment.