cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CAP Node.js - Insert vector embedding data into hana cloud is not working

johnwei
Explorer
197

Hello, everyone,

I referred these two links cap-ai-vector-engine-sample ,cap-llm-plugin-samples  to develop a CAP RAG application.

When I insert the embedding data into the db, I got an error message "argument type mismatch: Result is not a single value".

After my research, I found that if the dependency @SAP/cds-hana is added, data can be inserted into the database successfully, However, my App use Fiori elements and enbaled draft function, if the @SAP/cds-hana dependency is used, my Fiori app will encounter an error: SqlError: invalid column name: DRAFTADMINISTRATIVEDATA.INPROCESSBYUSER. When this dependency is removed, the Fiori app will not report an error, but I won't be able to insert data into the db. It seems that this is a dilemma, So, is there a conflict between @SAP/cds-hana and the draft-enabled function?  And is there any way to insert data into the db normally without using this dependency?

Any advice or suggestions would be appreciated.

schema.cds

entity DocumentChunk : cuid, managed {
    file            : Association to Files;
    text_chunk      : LargeString;
    metadata_column : LargeString;
    embedding       : Vector(1536);
}

service.js ( insert into db )

const embeddingResult = await capllmplugin.getEmbeddingWithConfig(
          embeddingModelConfig,
          chunk.pageContent
        );

embedding = embeddingResult?.data[0]?.embedding;

const entry = {
          file_ID: uuid,
          text_chunk: chunk.pageContent,
          metadata_column: fileName,
          embedding: array2VectorBuffer(embedding),
        };
textChunkEntries.push(entry);

// Insert the text chunk with embeddings into db
      const insertStatus = await INSERT.into(DocumentChunk).entries(
        textChunkEntries
      );

package.json

 "dependencies": {
    "@sap-cloud-sdk/http-client": "3.25.0",
    "@sap-cloud-sdk/resilience": "3.25.0",
    "@sap/cds": "^8",
    "@cap-js/hana": "^1",
    "@sap/xssec": "^4",
    "cap-llm-plugin": "^1.4.4",
    "express": "^4",
    "langchain": "^0.1.19",
  }

 

View Entire Topic
Dinu
Active Contributor

The following change would get you going with cap-js/hana

 

> embedding: array2VectorBuffer(embedding),
----
< embedding: JSON.stringify(embedding),

 

You could ask for supporting binary representation at https://github.com/cap-js/cds-dbs/issues

PS: I see that native queries support binary representation. You could try that too and let us know if that works better than text representation. 🙂

 

 

johnwei
Explorer

Hi Dinu,

wow, it's really an amazing change.

It does work after making change as you suggested, Thank you so much.

BTW, due to this issue previously, I found another workaround by using the trigger of Hana Cloud. So I will try what you said later.

Thank you again.