repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | --- |
| #2 | title: '❓ query' |
| #3 | --- |
| #4 | |
| #5 | `.query()` method empowers developers to ask questions and receive relevant answers through a user-friendly query API. Function signature is given below: |
| #6 | |
| #7 | ### Parameters |
| #8 | |
| #9 | <ParamField path="input_query" type="str"> |
| #10 | Question to ask |
| #11 | </ParamField> |
| #12 | <ParamField path="config" type="BaseLlmConfig" optional> |
| #13 | Configure different llm settings such as prompt, temprature, number_documents etc. |
| #14 | </ParamField> |
| #15 | <ParamField path="dry_run" type="bool" optional> |
| #16 | The purpose is to test the prompt structure without actually running LLM inference. Defaults to `False` |
| #17 | </ParamField> |
| #18 | <ParamField path="where" type="dict" optional> |
| #19 | A dictionary of key-value pairs to filter the chunks from the vector database. Defaults to `None` |
| #20 | </ParamField> |
| #21 | <ParamField path="citations" type="bool" optional> |
| #22 | Return citations along with the LLM answer. Defaults to `False` |
| #23 | </ParamField> |
| #24 | |
| #25 | ### Returns |
| #26 | |
| #27 | <ResponseField name="answer" type="str | tuple"> |
| #28 | If `citations=False`, return a stringified answer to the question asked. <br /> |
| #29 | If `citations=True`, returns a tuple with answer and citations respectively. |
| #30 | </ResponseField> |
| #31 | |
| #32 | ## Usage |
| #33 | |
| #34 | ### With citations |
| #35 | |
| #36 | If you want to get the answer to question and return both answer and citations, use the following code snippet: |
| #37 | |
| #38 | ```python With Citations |
| #39 | from embedchain import App |
| #40 | |
| #41 | # Initialize app |
| #42 | app = App() |
| #43 | |
| #44 | # Add data source |
| #45 | app.add("https://www.forbes.com/profile/elon-musk") |
| #46 | |
| #47 | # Get relevant answer for your query |
| #48 | answer, sources = app.query("What is the net worth of Elon?", citations=True) |
| #49 | print(answer) |
| #50 | # Answer: The net worth of Elon Musk is $221.9 billion. |
| #51 | |
| #52 | print(sources) |
| #53 | # [ |
| #54 | # ( |
| #55 | # 'Elon Musk PROFILEElon MuskCEO, Tesla$247.1B$2.3B (0.96%)Real Time Net Worthas of 12/7/23 ...', |
| #56 | # { |
| #57 | # 'url': 'https://www.forbes.com/profile/elon-musk', |
| #58 | # 'score': 0.89, |
| #59 | # ... |
| #60 | # } |
| #61 | # ), |
| #62 | # ( |
| #63 | # '74% of the company, which is now called X.Wealth HistoryHOVER TO REVEAL NET WORTH BY YEARForbes ...', |
| #64 | # { |
| #65 | # 'url': 'https://www.forbes.com/profile/elon-musk', |
| #66 | # 'score': 0.81, |
| #67 | # ... |
| #68 | # } |
| #69 | # ), |
| #70 | # ( |
| #71 | # 'founded in 2002, is worth nearly $150 billion after a $750 million tender offer in June 2023 ...', |
| #72 | # { |
| #73 | # 'url': 'https://www.forbes.com/profile/elon-musk', |
| #74 | # 'score': 0.73, |
| #75 | # ... |
| #76 | # } |
| #77 | # ) |
| #78 | # ] |
| #79 | ``` |
| #80 | |
| #81 | <Note> |
| #82 | When `citations=True`, note that the returned `sources` are a list of tuples where each tuple has two elements (in the following order): |
| #83 | 1. source chunk |
| #84 | 2. dictionary with metadata about the source chunk |
| #85 | - `url`: url of the source |
| #86 | - `doc_id`: document id (used for book keeping purposes) |
| #87 | - `score`: score of the source chunk with respect to the question |
| #88 | - other metadata you might have added at the time of adding the source |
| #89 | </Note> |
| #90 | |
| #91 | ### Without citations |
| #92 | |
| #93 | If you just want to return answers and don't want to return citations, you can use the following example: |
| #94 | |
| #95 | ```python Without Citations |
| #96 | from embedchain import App |
| #97 | |
| #98 | # Initialize app |
| #99 | app = App() |
| #100 | |
| #101 | # Add data source |
| #102 | app.add("https://www.forbes.com/profile/elon-musk") |
| #103 | |
| #104 | # Get relevant answer for your query |
| #105 | answer = app.query("What is the net worth of Elon?") |
| #106 | print(answer) |
| #107 | # Answer: The net worth of Elon Musk is $221.9 billion. |
| #108 | ``` |
| #109 | |
| #110 |