@digipair/skill-vespa 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.cjs.js +15 -13
  2. package/index.esm.js +15 -13
  3. package/package.json +1 -1
package/index.cjs.js CHANGED
@@ -34643,28 +34643,27 @@ let VespaService = class VespaService {
34643
34643
  ...parents,
34644
34644
  ...chunks.flat()
34645
34645
  ];
34646
- const embeddings = await this.embeddings(result.map((document)=>document.content));
34647
- return result.map((document, index)=>_extends({}, document, {
34648
- content_embedding: embeddings[index]
34649
- }));
34646
+ return result;
34650
34647
  }
34651
34648
  async embedding(text) {
34652
- const { HuggingFaceTransformersEmbeddings } = await eval(`import('@langchain/community/embeddings/hf_transformers')`);
34653
- const model = new HuggingFaceTransformersEmbeddings({
34654
- modelName: 'Xenova/multilingual-e5-large'
34655
- });
34656
- return await model.embedQuery(text);
34657
- }
34658
- async embeddings(texts) {
34659
- return Promise.all(texts.map((text)=>this.embedding(text)));
34649
+ if (this.embeddingsModel === null) {
34650
+ const { HuggingFaceTransformersEmbeddings } = await eval(`import('@langchain/community/embeddings/hf_transformers')`);
34651
+ this.embeddingsModel = new HuggingFaceTransformersEmbeddings({
34652
+ modelName: 'Xenova/multilingual-e5-large'
34653
+ });
34654
+ }
34655
+ return await this.embeddingsModel.embedQuery(text);
34660
34656
  }
34661
34657
  async pushDocuments(baseUrl, collection, documents) {
34662
34658
  const results = [];
34663
34659
  for (const document of documents){
34660
+ const content_embedding = await this.embedding(document.content);
34664
34661
  const response = await fetch(`${baseUrl}/document/v1/Digipair_default/${collection}/docid/${document.uuid}`, {
34665
34662
  method: 'POST',
34666
34663
  body: JSON.stringify({
34667
- fields: _extends({}, document)
34664
+ fields: _extends({}, document, {
34665
+ content_embedding
34666
+ })
34668
34667
  }),
34669
34668
  headers: {
34670
34669
  'Content-Type': 'application/json'
@@ -34724,6 +34723,9 @@ let VespaService = class VespaService {
34724
34723
  const results = await this.prepareDocuments(documents);
34725
34724
  return await this.pushDocuments(baseUrl, collection, results);
34726
34725
  }
34726
+ constructor(){
34727
+ this.embeddingsModel = null;
34728
+ }
34727
34729
  };
34728
34730
  const find = (params, pinsSettingsList, context)=>new VespaService().find(params, pinsSettingsList, context);
34729
34731
  const search = (params, pinsSettingsList, context)=>new VespaService().search(params, pinsSettingsList, context);
package/index.esm.js CHANGED
@@ -34639,28 +34639,27 @@ let VespaService = class VespaService {
34639
34639
  ...parents,
34640
34640
  ...chunks.flat()
34641
34641
  ];
34642
- const embeddings = await this.embeddings(result.map((document)=>document.content));
34643
- return result.map((document, index)=>_extends({}, document, {
34644
- content_embedding: embeddings[index]
34645
- }));
34642
+ return result;
34646
34643
  }
34647
34644
  async embedding(text) {
34648
- const { HuggingFaceTransformersEmbeddings } = await eval(`import('@langchain/community/embeddings/hf_transformers')`);
34649
- const model = new HuggingFaceTransformersEmbeddings({
34650
- modelName: 'Xenova/multilingual-e5-large'
34651
- });
34652
- return await model.embedQuery(text);
34653
- }
34654
- async embeddings(texts) {
34655
- return Promise.all(texts.map((text)=>this.embedding(text)));
34645
+ if (this.embeddingsModel === null) {
34646
+ const { HuggingFaceTransformersEmbeddings } = await eval(`import('@langchain/community/embeddings/hf_transformers')`);
34647
+ this.embeddingsModel = new HuggingFaceTransformersEmbeddings({
34648
+ modelName: 'Xenova/multilingual-e5-large'
34649
+ });
34650
+ }
34651
+ return await this.embeddingsModel.embedQuery(text);
34656
34652
  }
34657
34653
  async pushDocuments(baseUrl, collection, documents) {
34658
34654
  const results = [];
34659
34655
  for (const document of documents){
34656
+ const content_embedding = await this.embedding(document.content);
34660
34657
  const response = await fetch(`${baseUrl}/document/v1/Digipair_default/${collection}/docid/${document.uuid}`, {
34661
34658
  method: 'POST',
34662
34659
  body: JSON.stringify({
34663
- fields: _extends({}, document)
34660
+ fields: _extends({}, document, {
34661
+ content_embedding
34662
+ })
34664
34663
  }),
34665
34664
  headers: {
34666
34665
  'Content-Type': 'application/json'
@@ -34720,6 +34719,9 @@ let VespaService = class VespaService {
34720
34719
  const results = await this.prepareDocuments(documents);
34721
34720
  return await this.pushDocuments(baseUrl, collection, results);
34722
34721
  }
34722
+ constructor(){
34723
+ this.embeddingsModel = null;
34724
+ }
34723
34725
  };
34724
34726
  const find = (params, pinsSettingsList, context)=>new VespaService().find(params, pinsSettingsList, context);
34725
34727
  const search = (params, pinsSettingsList, context)=>new VespaService().search(params, pinsSettingsList, context);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digipair/skill-vespa",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "dependencies": {},
5
5
  "main": "./index.cjs.js",
6
6
  "module": "./index.esm.js"