Functions:searchCollection - bettyblocks/cli GitHub Wiki

Search Collection

The searchCollection function simplifies the process of searching within a collection of documents. It takes various parameters including the search query, the collection of documents to search through, the specific fields to consider in the search, and whether to chunk (split) large documents. This makes it versatile for different use cases.

  const { result } = await searchCollection({
    query,
    documents: collection?.data ?? [],
    fields: [propertyName],
    prefilterThreshold: 0.0,
    chunk,
  });

Parameters:

  • query: This is the parameter that defines what the search is looking for in the collection.
  • documents: The collection of documents to search in.
  • fields: The specific property name to focus the search on.
  • chunk: Whether to split a document into smaller chunks. This will improve the relevance of results.
  • prefilterThreshold: The max difference in scores between the top-scoring document and all other documents when employing a BM25 prefilter.

Example

  async function performSearch() {
    const collection = {
      data: [
        { id: 0, title: "Document 1", content: "This is the first document." },
        { id: 1, title: "Document 2", content: "This is the second document." }
      ]
    };

    const searchResults = await searchCollection({
      query: "first",
      documents: collection.data,
      fields: ["content"],
      prefilterThreshold: 0.0,
      chunk: false
    });

    console.log(searchResults.result);
  }