ppsingh commited on
Commit
c0b3c5a
·
1 Parent(s): f13b0c6

only filter_metadata in api and ui

Browse files
Files changed (1) hide show
  1. app.py +6 -37
app.py CHANGED
@@ -14,22 +14,11 @@ except Exception as e:
14
  # ---------------------------------------------------------------------
15
  # MCP - returns raw dictionary format
16
  # ---------------------------------------------------------------------
17
- def create_metadata_dict(sources_input, sources_value):
18
- """
19
- This helper function creates the filter dictionary based on user input.
20
- """
21
- if sources_input and sources_value:
22
-
23
- return {sources_input: sources_value}
24
- return None
25
-
26
 
27
  def retrieve(
28
  query:str,
29
- collection_name:str = None,
30
- filter_metadata:dict = None,
31
- sources_input:str = None,
32
- sources_value:str = None,
33
  ) -> list:
34
  """
35
  Retrieve semantically similar documents from the vector database for MCP clients.
@@ -44,9 +33,6 @@ def retrieve(
44
  Returns:
45
  list: List of dictionaries containing document content, metadata, and scores
46
  """
47
- if not filter_metadata:
48
- if sources_input and sources_value:
49
- filter_metadata = {sources_input: sources_value}
50
 
51
  # Call retriever function and return raw results
52
  results = get_context(
@@ -78,18 +64,8 @@ with gr.Blocks() as ui:
78
  placeholder="EUDR, Humboldt",
79
  info="Name of the collection"
80
  )
81
- sources_input = gr.Textbox(
82
- label="Sources Filter key to be looked in metadata (optional)",
83
- lines=1,
84
- placeholder="country",
85
- info="Filter by document source type (leave empty for all)"
86
- )
87
- sources_value = gr.Textbox(
88
- label="Value in filter to be looked for(optional)",
89
- lines=1,
90
- placeholder="Ecuador, Guatemala",
91
- info="Filter by document subtype (leave empty for all)"
92
- )
93
  submit_btn = gr.Button("Submit", variant="primary")
94
 
95
  # Output needs to be in json format to be added as tool in HuggingChat
@@ -101,18 +77,11 @@ with gr.Blocks() as ui:
101
  )
102
 
103
  # UI event handler
104
- # submit_btn.click(
105
- # fn=retrieve,
106
- # inputs=[query_input,collection_name, filter_metadata],
107
- # outputs=output,
108
- # api_name="retrieve"
109
- # )
110
  submit_btn.click(
111
- # 3. Use the updated state as an input to the retrieve function.
112
  fn=retrieve,
113
- inputs=[query_input, collection_name, None, sources_input, sources_value],
114
  outputs=output,
115
- queue=False
116
  )
117
 
118
 
 
14
  # ---------------------------------------------------------------------
15
  # MCP - returns raw dictionary format
16
  # ---------------------------------------------------------------------
 
 
 
 
 
 
 
 
 
17
 
18
  def retrieve(
19
  query:str,
20
+ collection_name:Optional[str] = None,
21
+ filter_metadata:Optional[dict] = None,
 
 
22
  ) -> list:
23
  """
24
  Retrieve semantically similar documents from the vector database for MCP clients.
 
33
  Returns:
34
  list: List of dictionaries containing document content, metadata, and scores
35
  """
 
 
 
36
 
37
  # Call retriever function and return raw results
38
  results = get_context(
 
64
  placeholder="EUDR, Humboldt",
65
  info="Name of the collection"
66
  )
67
+
68
+ filter_metadata = gr.JSON(label="Filter Metadata (optional)")
 
 
 
 
 
 
 
 
 
 
69
  submit_btn = gr.Button("Submit", variant="primary")
70
 
71
  # Output needs to be in json format to be added as tool in HuggingChat
 
77
  )
78
 
79
  # UI event handler
 
 
 
 
 
 
80
  submit_btn.click(
 
81
  fn=retrieve,
82
+ inputs=[query_input, collection_name, filter_metadata],
83
  outputs=output,
84
+ api_name="retrieve"
85
  )
86
 
87