search.mdx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. ---
  2. title: '🔍 search'
  3. ---
  4. `.search()` enables you to uncover the most pertinent context by performing a semantic search across your data sources based on a given query. Refer to the function signature below:
  5. ### Parameters
  6. <ParamField path="query" type="str">
  7. Question
  8. </ParamField>
  9. <ParamField path="num_documents" type="int" optional>
  10. Number of relevant documents to fetch. Defaults to `3`
  11. </ParamField>
  12. ### Returns
  13. <ResponseField name="answer" type="dict">
  14. Return list of dictionaries that contain the relevant chunk and their source information.
  15. </ResponseField>
  16. ## Usage
  17. Refer to the following example on how to use the search api:
  18. ```python Code example
  19. from embedchain import App
  20. # Initialize app
  21. app = App()
  22. # Add data source
  23. app.add("https://www.forbes.com/profile/elon-musk")
  24. # Get relevant context using semantic search
  25. context = app.search("What is the net worth of Elon?", num_documents=2)
  26. print(context)
  27. # Context:
  28. # [
  29. # {
  30. # 'context': 'Elon Musk PROFILEElon MuskCEO, Tesla$221.9BReal Time Net Worth ...',
  31. # 'metadata': {
  32. # 'source': 'https://www.forbes.com/profile/elon-musk',
  33. # 'document_id': 'some_document_id',
  34. # 'score': 0.404,
  35. # }
  36. # },
  37. # {
  38. # 'context': 'company, which is now called X.Wealth HistoryHOVER TO REVEAL NET WORTH ...',
  39. # 'metadata': {
  40. # 'source': 'https://www.forbes.com/profile/elon-musk',
  41. # 'document_id': 'some_document_id',
  42. # 'score': 0.435,
  43. # }
  44. # }
  45. # ]
  46. ```