This message was deleted.
# community-help
s
This message was deleted.
j
I just published
typesense/docsearch-scraper:0.9.0.rc1
which adds support for setting custom field definitions, using which you can add a new auto-embedding field like below in the scraper config:
Copy code
{
  "index_name": "typesense_docs",
  "start_urls": [
    {
      "url": "https://typesense.org/docs/(?P<version>.*?)/",
      "variables": {
        "version": [
          "0.21.0"
        ]
      }
    }
  ],
  "selectors": {
    "default": {
      "lvl0": ".content__default h1",
      "lvl1": ".content__default h2",
      "lvl2": ".content__default h3",
      "lvl3": ".content__default h4",
      "lvl4": ".content__default h5",
      "text": ".content__default p, .content__default ul li, .content__default table tbody tr"
    }
  },
  "custom_settings": {
    "field_definitions": [ // <==== ADD THIS
      {"name": "anchor", "type": "string", "optional": true},
      {"name": "content", "type": "string", "optional": true},
      {"name": "url", "type": "string", "facet": true},
      {"name": "url_without_anchor", "type": "string", "facet": true, "optional": true},
      {"name": "version", "type": "string[]", "facet": true, "optional": true},
      {"name": "hierarchy.lvl0", "type": "string", "facet": true, "optional": true},
      {"name": "hierarchy.lvl1", "type": "string", "facet": true, "optional": true},
      {"name": "hierarchy.lvl2", "type": "string", "facet": true, "optional": true},
      {"name": "hierarchy.lvl3", "type": "string", "facet": true, "optional": true},
      {"name": "hierarchy.lvl4", "type": "string", "facet": true, "optional": true},
      {"name": "hierarchy.lvl5", "type": "string", "facet": true, "optional": true},
      {"name": "hierarchy.lvl6", "type": "string", "facet": true, "optional": true},
      {"name": "type", "type": "string", "facet": true, "optional": true},
      {"name": ".*_tag", "type": "string", "facet": true, "optional": true},
      {"name": "language", "type": "string", "facet": true, "optional": true},
      {"name": "tags", "type": "string[]", "facet": true, "optional": true},
      {"name": "item_priority", "type": "int64"},
      {
        "name": "embedding",
        "type": "float[]",
        "embed": {
          "from": [
            "content",
            "hierarchy.lvl0",
            "hierarchy.lvl1",
            "hierarchy.lvl2",
            "hierarchy.lvl3",
            "hierarchy.lvl4",
            "hierarchy.lvl5",
            "hierarchy.lvl6",
            "tags"
          ],
          "model_config": {
            "model_name": "openai/text-embedding-ada-002",
            "api_key": "your_openai_api_key"
          }
        }
      }
    ]
  }
}
Then in your docsearch.js configuration you want to add a custom
query_by
parameter to
typesenseSearchParameters
or
typesenseSearchParams
(depending on what it's called in that particular version of docsearch.js):
Copy code
{ 
  query_by:  "hierarchy.lvl0,hierarchy.lvl1,hierarchy.lvl2,hierarchy.lvl3,hierarchy.lvl4,hierarchy.lvl5,hierarchy.lvl6,content,embedding",
  prefix: false
}
(The
prefix: false
is required for OpenAI)
Could you give it a shot and let me know how it goes? I can then update the docs
m
Quick question: is GPU required for using embeddings?
j
No, it's not required, especially if you're using OpenAI it's unecessary since it's openai that's doing generating the embeddings and sending them to Typesense
If you use one of the built-in models, then adding a GPU will speed things up especially if you have say 100s of thousands of docs or more, the difference in embedding generation becomes significant when using a CPU (slower) vs a GPU (much much faster)
m
@Jason Bosco, is there any built-in model you consider great for docs? Have you tried any for such a purpose?
j
I haven’t experimented with the docs use-case, but in general the GTE model seems to perform well for generic use cases
Just added instructions on how to setup semantic search with docsearch here: https://typesense.org/docs/guide/docsearch.html#semantic-search