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: '🔍 search' |
| #3 | --- |
| #4 | |
| #5 | `.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: |
| #6 | |
| #7 | ### Parameters |
| #8 | |
| #9 | <ParamField path="query" type="str"> |
| #10 | Question |
| #11 | </ParamField> |
| #12 | <ParamField path="num_documents" type="int" optional> |
| #13 | Number of relevant documents to fetch. Defaults to `3` |
| #14 | </ParamField> |
| #15 | <ParamField path="where" type="dict" optional> |
| #16 | Key value pair for metadata filtering. |
| #17 | </ParamField> |
| #18 | <ParamField path="raw_filter" type="dict" optional> |
| #19 | Pass raw filter query based on your vector database. |
| #20 | Currently, `raw_filter` param is only supported for Pinecone vector database. |
| #21 | </ParamField> |
| #22 | |
| #23 | ### Returns |
| #24 | |
| #25 | <ResponseField name="answer" type="dict"> |
| #26 | Return list of dictionaries that contain the relevant chunk and their source information. |
| #27 | </ResponseField> |
| #28 | |
| #29 | ## Usage |
| #30 | |
| #31 | ### Basic |
| #32 | |
| #33 | Refer to the following example on how to use the search api: |
| #34 | |
| #35 | ```python Code example |
| #36 | from embedchain import App |
| #37 | |
| #38 | app = App() |
| #39 | app.add("https://www.forbes.com/profile/elon-musk") |
| #40 | |
| #41 | context = app.search("What is the net worth of Elon?", num_documents=2) |
| #42 | print(context) |
| #43 | ``` |
| #44 | |
| #45 | ### Advanced |
| #46 | |
| #47 | #### Metadata filtering using `where` params |
| #48 | |
| #49 | Here is an advanced example of `search()` API with metadata filtering on pinecone database: |
| #50 | |
| #51 | ```python |
| #52 | import os |
| #53 | |
| #54 | from embedchain import App |
| #55 | |
| #56 | os.environ["PINECONE_API_KEY"] = "xxx" |
| #57 | |
| #58 | config = { |
| #59 | "vectordb": { |
| #60 | "provider": "pinecone", |
| #61 | "config": { |
| #62 | "metric": "dotproduct", |
| #63 | "vector_dimension": 1536, |
| #64 | "index_name": "ec-test", |
| #65 | "serverless_config": {"cloud": "aws", "region": "us-west-2"}, |
| #66 | }, |
| #67 | } |
| #68 | } |
| #69 | |
| #70 | app = App.from_config(config=config) |
| #71 | |
| #72 | app.add("https://www.forbes.com/profile/bill-gates", metadata={"type": "forbes", "person": "gates"}) |
| #73 | app.add("https://en.wikipedia.org/wiki/Bill_Gates", metadata={"type": "wiki", "person": "gates"}) |
| #74 | |
| #75 | results = app.search("What is the net worth of Bill Gates?", where={"person": "gates"}) |
| #76 | print("Num of search results: ", len(results)) |
| #77 | ``` |
| #78 | |
| #79 | #### Metadata filtering using `raw_filter` params |
| #80 | |
| #81 | Following is an example of metadata filtering by passing the raw filter query that pinecone vector database follows: |
| #82 | |
| #83 | ```python |
| #84 | import os |
| #85 | |
| #86 | from embedchain import App |
| #87 | |
| #88 | os.environ["PINECONE_API_KEY"] = "xxx" |
| #89 | |
| #90 | config = { |
| #91 | "vectordb": { |
| #92 | "provider": "pinecone", |
| #93 | "config": { |
| #94 | "metric": "dotproduct", |
| #95 | "vector_dimension": 1536, |
| #96 | "index_name": "ec-test", |
| #97 | "serverless_config": {"cloud": "aws", "region": "us-west-2"}, |
| #98 | }, |
| #99 | } |
| #100 | } |
| #101 | |
| #102 | app = App.from_config(config=config) |
| #103 | |
| #104 | app.add("https://www.forbes.com/profile/bill-gates", metadata={"year": 2022, "person": "gates"}) |
| #105 | app.add("https://en.wikipedia.org/wiki/Bill_Gates", metadata={"year": 2024, "person": "gates"}) |
| #106 | |
| #107 | print("Filter with person: gates and year > 2023") |
| #108 | raw_filter = {"$and": [{"person": "gates"}, {"year": {"$gt": 2023}}]} |
| #109 | results = app.search("What is the net worth of Bill Gates?", raw_filter=raw_filter) |
| #110 | print("Num of search results: ", len(results)) |
| #111 | ``` |
| #112 |