HamaWhiteGG / langchain-java

Java version of LangChain, while empowering LLM for Big Data.
Apache License 2.0
545 stars 106 forks source link

在 Pinecone 中使用了从Collections中恢复的索引发生异常 #122

Closed TheBlindM closed 11 months ago

TheBlindM commented 11 months ago
java.lang.RuntimeException: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "source_collection" (class com.hw.pinecone.entity.index.Database), not marked as ignorable (7 known properties: "metric", "pod_type", "shards", "dimension", "name", "pods", "replicas"])
 at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 1, column: 120] (through reference chain: com.hw.pinecone.entity.index.IndexDescription["database"]->com.hw.pinecone.entity.index.Database["source_collection"])
    at io.reactivex.internal.util.ExceptionHelper.wrapOrThrow(ExceptionHelper.java:46)
    at io.reactivex.internal.observers.BlockingMultiObserver.blockingGet(BlockingMultiObserver.java:93)
    at io.reactivex.Single.blockingGet(Single.java:2870)
    at com.hw.pinecone.PineconeClient.describeIndex(PineconeClient.java:183)
    at com.hw.pinecone.PineconeClient.indexClient(PineconeClient.java:91)
    at com.hw.langchain.vectorstores.pinecone.Pinecone.init(Pinecone.java:79)
    at com.beavers.aichat.service.VectorDatabaseService.match(VectorDatabaseService.java:61)

版本:pinecone-client:0.1.11

TheBlindM commented 11 months ago

临时解决方案: 在项目下建立同级目录,把类粘过 增加@JsonIgnoreProperties(ignoreUnknown = true)修复

HamaWhiteGG commented 11 months ago

@TheBlindM Can you show the return content of 'describeIndex'? I couldn't find any information about it on the Pinecone API official website.

https://docs.pinecone.io/reference/describe_index

HamaWhiteGG commented 11 months ago

@TheBlindM I also add objectMapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false) for PineconeClient to ignore unknown fields by default.

public static ObjectMapper defaultObjectMapper() {
    // Used for automatic discovery and registration of Jackson modules
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.findAndRegisterModules();
    // Ignore unknown fields
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    return objectMapper;
}
TheBlindM commented 11 months ago

该index 是从Collections中恢复的索引,返回的结构和普通新建的略微不同

{
  "database": {
    "name": "myindex",
    "metric": "cosine",
    "dimension": 1536,
    "replicas": 1,
    "shards": 1,
    "pods": 1,
    "source_collection": "myindex"
  },
  "status": {
    "waiting": [],
    "crashed": [],
    "host": "myindex-6e66697.svc.us-west1-gcp-free.pinecone.io",
    "port": 433,
    "state": "Ready",
    "ready": true
  }
}