@digipair/skill-vespa 0.0.1 → 0.0.2

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.
package/index.esm.js CHANGED
@@ -34561,14 +34561,17 @@ let VespaService = class VespaService {
34561
34561
  const response = await fetch(`${baseUrl}/search/`, {
34562
34562
  method: 'POST',
34563
34563
  body: JSON.stringify(_extends({
34564
- yql: `select * from ${collection} Digipair_default where ${query}`
34564
+ yql: `select * from ${collection} where ${query}`
34565
34565
  }, options)),
34566
34566
  headers: {
34567
34567
  'Content-Type': 'application/json'
34568
34568
  }
34569
34569
  });
34570
34570
  if (!response.ok) {
34571
- console.error('Error - VespaService:getDocuments - fetching', await response.json());
34571
+ var _error_root;
34572
+ const error = await response.json();
34573
+ var _error_root_errors;
34574
+ console.error('Error - VespaService:getDocuments - fetching', (_error_root_errors = (_error_root = error.root) == null ? void 0 : _error_root.errors) != null ? _error_root_errors : error);
34572
34575
  throw new Error(`Error - VespaService:getDocuments - fetching ${collection}`);
34573
34576
  }
34574
34577
  const messages = ((await response.json()).root.children || []).map((child)=>child.fields);
@@ -34591,13 +34594,6 @@ let VespaService = class VespaService {
34591
34594
  }
34592
34595
  return documents;
34593
34596
  }
34594
- async embedding(text) {
34595
- const { HuggingFaceTransformersEmbeddings } = await eval(`import('@langchain/community/embeddings/hf_transformers')`);
34596
- const model = new HuggingFaceTransformersEmbeddings({
34597
- modelName: 'Xenova/multilingual-e5-large'
34598
- });
34599
- return await model.embedQuery(text);
34600
- }
34601
34597
  async prepareDocuments(documents) {
34602
34598
  const parents = documents.map((document)=>{
34603
34599
  const uuid = v4();
@@ -34648,12 +34644,15 @@ let VespaService = class VespaService {
34648
34644
  content_embedding: embeddings[index]
34649
34645
  }));
34650
34646
  }
34651
- async embeddings(texts) {
34647
+ async embedding(text) {
34652
34648
  const { HuggingFaceTransformersEmbeddings } = await eval(`import('@langchain/community/embeddings/hf_transformers')`);
34653
34649
  const model = new HuggingFaceTransformersEmbeddings({
34654
34650
  modelName: 'Xenova/multilingual-e5-large'
34655
34651
  });
34656
- return Promise.all(texts.map((text)=>model.embedQuery(text)));
34652
+ return await model.embedQuery(text);
34653
+ }
34654
+ async embeddings(texts) {
34655
+ return Promise.all(texts.map((text)=>this.embedding(text)));
34657
34656
  }
34658
34657
  async pushDocuments(baseUrl, collection, documents) {
34659
34658
  const results = [];
@@ -34661,7 +34660,7 @@ let VespaService = class VespaService {
34661
34660
  const response = await fetch(`${baseUrl}/document/v1/Digipair_default/${collection}/docid/${document.uuid}`, {
34662
34661
  method: 'POST',
34663
34662
  body: JSON.stringify({
34664
- fields: document
34663
+ fields: _extends({}, document)
34665
34664
  }),
34666
34665
  headers: {
34667
34666
  'Content-Type': 'application/json'
@@ -34674,8 +34673,12 @@ let VespaService = class VespaService {
34674
34673
  async find(params, _pinsSettingsList, context) {
34675
34674
  var _context_private;
34676
34675
  var _context_private_VESPA_SERVER;
34677
- const { baseUrl = (_context_private_VESPA_SERVER = (_context_private = context.private) == null ? void 0 : _context_private.VESPA_SERVER) != null ? _context_private_VESPA_SERVER : VESPA_SERVER, collection = 'knowledge', limit = 100, query } = params;
34678
- const results = await this.searchDocuments(baseUrl, collection, `is_parent = true and userQuery() limit ${limit}`, {
34676
+ const { baseUrl = (_context_private_VESPA_SERVER = (_context_private = context.private) == null ? void 0 : _context_private.VESPA_SERVER) != null ? _context_private_VESPA_SERVER : VESPA_SERVER, collection = 'knowledge', limit = 100, orderby = '', query } = params;
34677
+ if (orderby !== '' && !/^([a-zA-Z0-9_-]+)(,\s*[a-zA-Z0-9_-]+)*(\s+(asc|desc))?$/.test(orderby)) {
34678
+ throw new Error('vespa:find - Invalid orderby parameter');
34679
+ }
34680
+ const orderbySecured = orderby === '' ? '' : `order by ${orderby}`;
34681
+ const results = await this.searchDocuments(baseUrl, collection, `is_parent = true and userQuery() ${orderbySecured} limit ${parseInt(limit)}`, {
34679
34682
  query
34680
34683
  });
34681
34684
  return results;
@@ -34683,12 +34686,17 @@ let VespaService = class VespaService {
34683
34686
  async search(params, _pinsSettingsList, context) {
34684
34687
  var _context_private;
34685
34688
  var _context_private_VESPA_SERVER;
34686
- const { baseUrl = (_context_private_VESPA_SERVER = (_context_private = context.private) == null ? void 0 : _context_private.VESPA_SERVER) != null ? _context_private_VESPA_SERVER : VESPA_SERVER, collection = 'knowledge', limit = 100, targetHits = 50, query } = params;
34689
+ const { baseUrl = (_context_private_VESPA_SERVER = (_context_private = context.private) == null ? void 0 : _context_private.VESPA_SERVER) != null ? _context_private_VESPA_SERVER : VESPA_SERVER, collection = 'knowledge', limit = 100, orderby = '', targetHits = 50, language = 'fr', query } = params;
34690
+ if (orderby !== '' && !/^([a-zA-Z0-9_-]+)(,\s*[a-zA-Z0-9_-]+)*(\s+(asc|desc))?$/.test(orderby)) {
34691
+ throw new Error('vespa:find - Invalid orderby parameter');
34692
+ }
34693
+ const orderbySecured = orderby === '' ? '' : `order by ${orderby}`;
34687
34694
  const queryEmbedding = await this.embedding(query);
34688
- const results = await this.searchParentDocuments(baseUrl, collection, `((userQuery()) or ({targetHits:${targetHits}}nearestNeighbor(content_embedding,q))) limit ${limit}`, {
34695
+ const results = await this.searchParentDocuments(baseUrl, collection, `((userQuery()) or ({targetHits:${targetHits}}nearestNeighbor(content_embedding,q))) ${orderbySecured} limit ${parseInt(limit)}`, {
34689
34696
  'ranking.profile': 'fusion',
34690
34697
  'input.query(q)': queryEmbedding,
34691
- 'query': query
34698
+ query: query,
34699
+ language
34692
34700
  });
34693
34701
  return results;
34694
34702
  }
@@ -34715,7 +34723,7 @@ let VespaService = class VespaService {
34715
34723
  };
34716
34724
  const find = (params, pinsSettingsList, context)=>new VespaService().find(params, pinsSettingsList, context);
34717
34725
  const search = (params, pinsSettingsList, context)=>new VespaService().search(params, pinsSettingsList, context);
34718
- const push = (params, pinsSettingsList, context)=>new VespaService().push(params, pinsSettingsList, context);
34719
34726
  const textSplitter = (params, pinsSettingsList, context)=>new VespaService().textSplitter(params, pinsSettingsList, context);
34727
+ const push = (params, pinsSettingsList, context)=>new VespaService().push(params, pinsSettingsList, context);
34720
34728
 
34721
34729
  export { find, push, search, textSplitter };
@@ -1,6 +1,6 @@
1
1
  type PinsSettings = any;
2
2
  export declare const find: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
3
3
  export declare const search: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
4
- export declare const push: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
5
4
  export declare const textSplitter: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
5
+ export declare const push: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
6
6
  export {};
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@digipair/skill-vespa",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "dependencies": {},
5
- "type": "module",
6
5
  "main": "./index.cjs.js",
7
6
  "module": "./index.esm.js"
8
7
  }
File without changes