Hi all, same as <@U05LNQL0UQ0> - going through the...
# community-help
u
Hi all, same as @Shiva Dixith - going through the docs for the Natural Language Search in v29 and doing a POC example. It looks like that the search is expecting to search a VERY FLAT collection Examples: a
books
collection with
id
,
name
, and
author
v.s. a
books
collection with
id
,
name
,
author_id
referencing
authors
collection. The NLS doesn't seem to work well when asking give me book from author Joe Doe
a
the query ends up trying to look for author_id = "Joe Doe" when in fact "Joe Doe" has an ID of 123. Any thoughts or I simply need to *FLATTEN the data?
j
Do you mean you're using JOINs?
The prompt we use built-in currently doesn't have any examples of JOINs... So you'll have to augment the NL model prompt when you create it with some examples for how to write the Typesense query given your data structure
Usually just 3-5 examples works
a
yeap, it looks like that data need to be JOINED but not sure how to do it
Copy code
curl "<https://my.typesense/collections/books/documents/search>" \
      -H "X-TYPESENSE-API-KEY: xyz" \
      -G \
      --data-urlencode "q=show me all books for author Allen with amount more than $10." \
      --data-urlencode "nl_query=true" \
      --data-urlencode "query_by=author_id" \
      --data-urlencode "nl_model_id=my-openai-typesense-model"
@Jason Bosco can you elaborate more on ...So you'll have to augment the NL model prompt when you create it with some examples... Any tutorials?
j
When you create the NL model, there'a. parameter called "system_prompt": https://typesense.org/docs/29.0/api/natural-language-search.html#supported-model-types
Inside there you'd have something like this:
Copy code
Here are more examples of queries and how you should translate them to Typesense queries:

1) show me all books for author Allen with amount more than $10

"filter_by": "amount:>10 && $authors(first_name:Allen)"
You're essentially "few-shotting" the LLM with some examples
a
I got it. Hmmmm....the system prompt can get pretty long when you have
author_id
,
category_id
,
group_id
and
xyz_id
all referencing other tables. I feel like the best way is to have all the data in just one collection - flatten - for NLS use case
j
The LLM does extrapolate pretty well with a few examples. So I'd recommend trying it first
a
thanks!!! definitely will give it a try. By the way, shut out to YOU!!! Getting help from the co-founder - too AWESOME!!!
j
Happy to help! 😄
a
I will report back my findings later in the same thread. Thanks again for the help!
👍 1
results is kinda good with a bit trouble in dollar amount - I have a more sophisticated example
transactions
with system prompts
Copy code
"\"amount_cents\" refers to the amount of the transaction in US dollar cents.Here are more examples of queries and how you should translate them to Typesense queries:\n1) show me all transactions for Allen with amount more than $1000\n\"filter_by\": \"amount_cents:>100000 && $users(name: Allen)\"\n2) show me all transactions in category \"Admin\"\n\"filter_by\": \"$categories(name: Admin) || $sub_categories(name: Admin)\"\n3) show me all transactions assigned to property \"4819 Emerald St\"\n\"filter_by\": \"$properties(address: 4819 Emerald St)\"\n4) show me all transactions assigned to \"First\" portfolio\n\"filter_by\": \"$portfolios(name: First)\"\n5) show me all transactions for user Allen with amount more than $1000, and in category related to storage\n\"filter_by\": \"amount_cents:>100000 && $users(name: Allen) && ($categories(name: Storage) || $sub_categories(name: Storage))\""
but ...
not sure why
amount_cents
is not able to be parsed properly. is the
$
sign throwing things off?🤔
in some case, NLS is able to parse into correct
filter_by
, but only after I specified the column name - not idea. Even then, the expected result is not accurate. 0 results when there should be some records. So far....this NLS is a bit confusing to work with 😵‍💫