typesense-instantsearch-adapter 2.9.0-3 → 2.9.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 CHANGED
@@ -582,7 +582,7 @@ const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
582
582
 
583
583
  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.
584
584
 
585
- 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).
585
+ Here's a demo that you can run locally to see this in action: [https://github.com/typesense/showcase-hn-comments-semantic-search](https://github.com/typesense/showcase-hn-comments-semantic-search).
586
586
 
587
587
  Here's how to do this in Instantsearch.js:
588
588
 
@@ -601,39 +601,39 @@ const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
601
601
  },
602
602
  additionalSearchParameters,
603
603
  });
604
+ // from https://github.com/typesense/showcase-hn-comments-semantic-search/blob/8a33006cae58b425c53f56a64e1273e808cd9375/src/js/index.js#L101
604
605
  const searchClient = typesenseInstantsearchAdapter.searchClient;
605
- const search = instantsearch({
606
- searchClient,
607
- indexName: "products",
608
- routing: true,
609
- async searchFunction(helper) {
610
- const query = helper.getQuery().query;
611
- const page = helper.getPage(); // Retrieve the current page
612
- const totalNearestNeighborsToFetch = 1000;
613
-
614
- if (query !== "") {
615
- // Get embedding for the query
616
- let response = await fetch(
617
- "http://localhost:8000/embedding?" + new URLSearchParams({ q: query }), // <=== Embedding API
618
- );
619
-
620
- let parsedResponse = await response.json();
621
-
622
- console.log(parsedResponse);
623
-
624
- // Send the embedding to Typesense to do a nearest neighbor search
625
- helper
626
- .setQueryParameter(
627
- "typesenseVectorQuery", // <=== Special parameter that only works in typesense-instantsearch-adapter@2.7.0-3 and above
628
- `vectors:([${parsedResponse["embedding"].join(",")}], k:${totalNearestNeighborsToFetch})`,
629
- )
630
- .setPage(page)
631
- .search();
632
- } else {
633
- helper.setQueryParameter("typesenseVectorQuery", null).setPage(page).search();
634
- }
635
- },
636
- });
606
+ search = instantsearch({
607
+ searchClient,
608
+ indexName: INDEX_NAME,
609
+ routing: true,
610
+ async searchFunction(helper) {
611
+ // This fetches 200 (nearest neighbor) results for semantic / hybrid search
612
+
613
+ let query = helper.getQuery().query;
614
+ const page = helper.getPage(); // Retrieve the current page
615
+
616
+ if (
617
+ query !== "" &&
618
+ ["semantic", "hybrid"].includes($("#search-type-select").val())
619
+ ) {
620
+ console.log(helper.getQuery().query);
621
+ helper
622
+ .setQueryParameter(
623
+ "typesenseVectorQuery", // <=== Special parameter that only works in typesense-instantsearch-adapter@2.7.0-3 and above
624
+ `embedding:([], k:200)`,
625
+ )
626
+ .setPage(page)
627
+ .search();
628
+ console.log(helper.getQuery().query);
629
+ } else {
630
+ helper
631
+ .setQueryParameter("typesenseVectorQuery", null)
632
+ .setPage(page)
633
+ .search();
634
+ }
635
+ },
636
+ });
637
637
  ```
638
638
 
639
639
  ## Compatibility
@@ -657,7 +657,6 @@ If a particular version of the above libraries don't work with the adapter, plea
657
657
 
658
658
  This adapter works with all widgets in [this list](https://www.algolia.com/doc/api-reference/widgets/js/), _except_ for the following:
659
659
 
660
- - `queryRuleCustomData`
661
660
  - `queryRuleContext`
662
661
 
663
662
  ## Development