|
657 | 657 | }, |
658 | 658 | { |
659 | 659 | "cell_type": "code", |
660 | | - "execution_count": 21, |
| 660 | + "execution_count": null, |
661 | 661 | "metadata": { |
662 | 662 | "id": "ptPCVVRKghQY" |
663 | 663 | }, |
|
668 | 668 | "def retrieval_function(\n", |
669 | 669 | " query: Optional[str] = None,\n", |
670 | 670 | " metadata_filters: Optional[Dict[str, Any]] = None,\n", |
671 | | - " top_k: Optional[int] = 5\n", |
| 671 | + " top_k: int = 5\n", |
672 | 672 | ") -> List[Document]:\n", |
673 | 673 | "\n", |
674 | 674 | " retrieved_documents = []\n", |
|
685 | 685 | " # If there's only `metadata_filters`\n", |
686 | 686 | " else:\n", |
687 | 687 | " retrieved_documents = filter_retriever.run(filters=metadata_filters)\n", |
688 | | - " if len(retrieved_documents.get(\"documents\")) > top_k:\n", |
689 | | - " retrieved_documents[\"documents\"] = retrieved_documents[\"documents\"][:top_k]\n", |
| 688 | + " retrieved_documents[\"documents\"] = retrieved_documents[\"documents\"][:top_k]\n", |
690 | 689 | "\n", |
691 | 690 | " return retrieved_documents" |
692 | 691 | ] |
|
697 | 696 | "id": "bcCbVu9PDWTG" |
698 | 697 | }, |
699 | 698 | "source": [ |
700 | | - "Define the JSON schema for tool parameters, including `query`, `top_k`, and `metadata_filters`, to validate and structure tool calls." |
| 699 | + "Define the JSON schema for your tool parameters, such as `query`, `top_k`, and `metadata_filters`, to ensure tool calls are properly structured and validated.\n", |
| 700 | + "\n", |
| 701 | + "> In most cases, you don’t need to define `parameters` manually. When you use the [@tool decorator](https://docs.haystack.deepset.ai/docs/tool#tool-decorator) or [create_tool_from_function](https://docs.haystack.deepset.ai/docs/tool#create_tool_from_function), Haystack automatically infers the tool’s name, description, and parameters from the function and generates a matching JSON schema for you." |
701 | 702 | ] |
702 | 703 | }, |
703 | 704 | { |
|
0 commit comments