typesense-instantsearch-adapter 2.7.0-2 → 2.7.0-3

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 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,62 @@ const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
440
444
  });
441
445
  ```
442
446
 
443
- 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).
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
+ let query = helper.getQuery().query;
479
+
480
+ if (query !== '') {
481
+ // Get embedding for the query
482
+ let response = await fetch(
483
+ 'http://localhost:8000/embedding?' + new URLSearchParams({ q: query }) // <=== Embedding API
484
+ );
485
+
486
+ let parsedResponse = await response.json();
487
+
488
+ console.log(parsedResponse);
489
+
490
+ // Send the embedding to Typesense to do a nearest neighbor search
491
+ helper
492
+ .setQueryParameter(
493
+ 'typesenseVectorQuery', // <=== Special parameter that only works in typesense-instantsearch-adapter@2.7.0-3 and above
494
+ `vectors:([${parsedResponse['embedding'].join(',')}])`
495
+ )
496
+ .search();
497
+ } else {
498
+ helper.setQueryParameter('typesenseVectorQuery', null).search();
499
+ }
500
+ },
501
+ });
502
+ ```
444
503
 
445
504
  ## Compatibility
446
505
 
@@ -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