Search for chunks

Chunk search

search for chunks without query

You can search for chunks without a query, meaning you just use filters and metadata to display the desired selection of chunks. To do that, simply follow the recipe below:

from recital.api.search import search_chunks
from recital.models import search_query_string_query

query = search_query_string_query.SearchQueryStringQuery(query="floriane frais",
                                                         output_fields=["name","metadata"],
                                                         keywords=[],
                                                         keyword_op="and",
                                                         folder_ids=[]
                                                        )
result = search_chunks.sync(client=client, json_body=query)

for chunk in result.chunks:
    print(chunk["text"])
  • filters: use previously applied metadata as filters
  • keywords: view it as a "ctrl + F", the string must be present at least once in the document
  • folders:_id restrict you search to one or multiple folders only
  • file_ids: the same way you can restrict on folders you can restrict on files
  • pagination: there is a pagination system in order to lighten the size of the output

search for documents with query

You can perform a search within documents with a query. The result will be all the ranked chunks, starting from the top, that answer to the query.

from recital.api.search import search_chunks
from recital.models import search_query_string_query

query = search_query_string_query.SearchQueryStringQuery(file_ids=[10,8],
                                                         query="my cool query",
                                                         output_fields=[],
                                                         keywords=[], 
                                                         keyword_op="and",
                                                         folder_ids=[]
                                                        )
result = search_chunks.sync(client=client, json_body=query)

for chunk in result.chunks:
    print(chunk.name, chunk.id)

Did this page help you?