typesense-instantsearch-adapter 2.7.0-2 → 2.7.0-4
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/README.md +66 -1
- package/dist/typesense-instantsearch-adapter.js +11 -5
- package/dist/typesense-instantsearch-adapter.js.map +1 -1
- package/dist/typesense-instantsearch-adapter.min.js +1 -1
- package/dist/typesense-instantsearch-adapter.min.js.map +1 -1
- package/lib/SearchRequestAdapter.js +6 -0
- package/lib/SearchRequestAdapter.js.map +1 -1
- package/package.json +2 -2
- package/src/SearchRequestAdapter.js +6 -0
package/README.md
CHANGED
|
@@ -398,8 +398,12 @@ const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
|
|
|
398
398
|
});
|
|
399
399
|
```
|
|
400
400
|
|
|
401
|
+
Read more about all available options for `renderingContent` in [Algolia's documentation here](https://www.algolia.com/doc/api-reference/api-parameters/renderingContent/?client=javascript#examples).
|
|
402
|
+
|
|
401
403
|
### Special characters in field names / values
|
|
402
404
|
|
|
405
|
+
> Available as of typesense-instantsearch-adapter `2.7.0-2`
|
|
406
|
+
|
|
403
407
|
- If any string fields in your documents have a colon `:` in their values (for eg, let's say there's a field called `{ brand: "a:b" }`, then you would need to add a parameter like below when instantiating the adapter:
|
|
404
408
|
|
|
405
409
|
```js
|
|
@@ -440,7 +444,68 @@ const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
|
|
|
440
444
|
});
|
|
441
445
|
```
|
|
442
446
|
|
|
443
|
-
|
|
447
|
+
### Vector Search
|
|
448
|
+
|
|
449
|
+
> Available as of typesense-instantsearch-adapter `2.7.0-3`
|
|
450
|
+
|
|
451
|
+
The general idea is to first hook into the query life-cycle of Instantsearch, intercept the typed query and send it to an embedding API, fetch the embeddings and then send the vectors to Typesense to do a nearest neighbor vector search.
|
|
452
|
+
|
|
453
|
+
Here's a demo that you can run locally to see this in action: [https://github.com/typesense/typesense-instantsearch-semantic-search-demo](https://github.com/typesense/typesense-instantsearch-semantic-search-demo).
|
|
454
|
+
|
|
455
|
+
Here's how to do this in Instantsearch.js:
|
|
456
|
+
|
|
457
|
+
```javascript
|
|
458
|
+
const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
|
|
459
|
+
server: {
|
|
460
|
+
apiKey: "xyz",
|
|
461
|
+
nodes: [
|
|
462
|
+
{
|
|
463
|
+
host: "localhost",
|
|
464
|
+
port: "8108",
|
|
465
|
+
path: "/",
|
|
466
|
+
protocol: "http",
|
|
467
|
+
},
|
|
468
|
+
],
|
|
469
|
+
},
|
|
470
|
+
additionalSearchParameters,
|
|
471
|
+
});
|
|
472
|
+
const searchClient = typesenseInstantsearchAdapter.searchClient;
|
|
473
|
+
const search = instantsearch({
|
|
474
|
+
searchClient,
|
|
475
|
+
indexName: 'products',
|
|
476
|
+
routing: true,
|
|
477
|
+
async searchFunction(helper) {
|
|
478
|
+
const query = helper.getQuery().query;
|
|
479
|
+
const page = helper.getPage(); // Retrieve the current page
|
|
480
|
+
const totalNearestNeighborsToFetch = 1000;
|
|
481
|
+
|
|
482
|
+
if (query !== '') {
|
|
483
|
+
// Get embedding for the query
|
|
484
|
+
let response = await fetch(
|
|
485
|
+
'http://localhost:8000/embedding?' + new URLSearchParams({ q: query }) // <=== Embedding API
|
|
486
|
+
);
|
|
487
|
+
|
|
488
|
+
let parsedResponse = await response.json();
|
|
489
|
+
|
|
490
|
+
console.log(parsedResponse);
|
|
491
|
+
|
|
492
|
+
// Send the embedding to Typesense to do a nearest neighbor search
|
|
493
|
+
helper
|
|
494
|
+
.setQueryParameter(
|
|
495
|
+
'typesenseVectorQuery', // <=== Special parameter that only works in typesense-instantsearch-adapter@2.7.0-3 and above
|
|
496
|
+
`vectors:([${parsedResponse['embedding'].join(',')}], k:${totalNearestNeighborsToFetch})`
|
|
497
|
+
)
|
|
498
|
+
.setPage(page)
|
|
499
|
+
.search();
|
|
500
|
+
} else {
|
|
501
|
+
helper
|
|
502
|
+
.setQueryParameter('typesenseVectorQuery', null)
|
|
503
|
+
.setPage(page)
|
|
504
|
+
.search();
|
|
505
|
+
}
|
|
506
|
+
},
|
|
507
|
+
});
|
|
508
|
+
```
|
|
444
509
|
|
|
445
510
|
## Compatibility
|
|
446
511
|
|
|
@@ -2808,6 +2808,12 @@ var SearchRequestAdapter = /*#__PURE__*/function () {
|
|
|
2808
2808
|
if (params.facetQuery) {
|
|
2809
2809
|
typesenseSearchParams.facet_query = "".concat(params.facetName, ":").concat(params.facetQuery);
|
|
2810
2810
|
typesenseSearchParams.per_page = 0;
|
|
2811
|
+
} // If a custom vector query is specified, set q=*
|
|
2812
|
+
|
|
2813
|
+
|
|
2814
|
+
if (params.typesenseVectorQuery) {
|
|
2815
|
+
typesenseSearchParams.vector_query = params.typesenseVectorQuery;
|
|
2816
|
+
typesenseSearchParams.q = "*";
|
|
2811
2817
|
} // console.log(params);
|
|
2812
2818
|
// console.log(typesenseSearchParams);
|
|
2813
2819
|
// Filter out empty or null values, so we don't accidentally override values set in presets
|
|
@@ -5339,22 +5345,22 @@ var Configuration = /** @class */ (function () {
|
|
|
5339
5345
|
Configuration.prototype.isNodeMissingAnyParameters = function (node) {
|
|
5340
5346
|
return (!['protocol', 'host', 'port', 'path'].every(function (key) {
|
|
5341
5347
|
return node.hasOwnProperty(key);
|
|
5342
|
-
}) && node
|
|
5348
|
+
}) && node['url'] == null);
|
|
5343
5349
|
};
|
|
5344
5350
|
Configuration.prototype.setDefaultPathInNode = function (node) {
|
|
5345
5351
|
if (node != null && !node.hasOwnProperty('path')) {
|
|
5346
|
-
node
|
|
5352
|
+
node['path'] = '';
|
|
5347
5353
|
}
|
|
5348
5354
|
return node;
|
|
5349
5355
|
};
|
|
5350
5356
|
Configuration.prototype.setDefaultPortInNode = function (node) {
|
|
5351
5357
|
if (node != null && !node.hasOwnProperty('port') && node.hasOwnProperty('protocol')) {
|
|
5352
|
-
switch (node
|
|
5358
|
+
switch (node['protocol']) {
|
|
5353
5359
|
case 'https':
|
|
5354
|
-
node
|
|
5360
|
+
node['port'] = 443;
|
|
5355
5361
|
break;
|
|
5356
5362
|
case 'http':
|
|
5357
|
-
node
|
|
5363
|
+
node['port'] = 80;
|
|
5358
5364
|
break;
|
|
5359
5365
|
}
|
|
5360
5366
|
}
|