1
- ## Using LLMs to Convert Natural Language Queries into Structured Queries
1
+ # Using LLMs to Convert Natural Language Queries into Structured Queries
2
2
3
- ### Context
3
+ ## Context
4
4
5
5
Over the past year, I have been working on building an application platform that
6
6
supports searching through OpenStreetMap data via an API endpoint and an
@@ -27,7 +27,7 @@ it difficult to present the data in a human-readable and usable way. There can
27
27
be tens of thousands, if not hundreds of thousands, of tags with multiple values
28
28
for each.
29
29
30
- ### Initial Approach
30
+ ## Initial Approach
31
31
32
32
I wanted to take a different approach: Could I have something that converted a
33
33
user's query, such as "grocery store," and mapped it to predefined tags?
@@ -48,7 +48,7 @@ to exclude mainstream coffee shops to find local businesses? This would require
48
48
maintaining a list of coffee shops to exclude or providing an exclusion
49
49
mechanism for users—making the interface complex.
50
50
51
- ### Experimenting with LLMs
51
+ ## Experimenting with LLMs
52
52
53
53
Given these limitations, I explored the possibility of using a Large Language
54
54
Model (LLM) to process natural language queries and convert them into structured
@@ -80,7 +80,7 @@ Example query:
80
80
81
81
[ Placeholder for an example with ChatGPT’s result.]
82
82
83
- ### Integrating LLMs into My Application
83
+ ## Integrating LLMs into My Application
84
84
85
85
With structured JSON working, I incorporated it into my application—a text box
86
86
where users could describe their desired neighborhood, and it would return
@@ -106,7 +106,7 @@ I then asked ChatGPT to refine my prompt:
106
106
107
107
[ Placeholder for shortened example of refined prompt.]
108
108
109
- ### Enhancing Query Accuracy
109
+ ## Enhancing Query Accuracy
110
110
111
111
To improve accuracy, I identified meaningful OpenStreetMap tags by researching
112
112
community discussions and manually curating a list of about 50 high-value tags
@@ -127,15 +127,15 @@ Testing showed that responses were now more specific. For example:
127
127
128
128
[ Placeholder for resulting query JSON.]
129
129
130
- ### Handling Geographic Areas
130
+ ## Handling Geographic Areas
131
131
132
132
To improve area selection, I extended the JSON output schema to include multiple
133
133
areas. Instead of requiring users to select one state, I allowed descriptions
134
134
like "Southwestern states" to infer multiple areas.
135
135
136
136
[ Placeholder for a query that includes southwestern states.]
137
137
138
- ### Optimizing Performance
138
+ ## Optimizing Performance
139
139
140
140
While my implementation worked, optimizations were necessary:
141
141
@@ -161,7 +161,7 @@ While my implementation worked, optimizations were necessary:
161
161
characters.
162
162
- This prevented excessive API costs and safeguarded against abuse.
163
163
164
- ### Conclusion
164
+ ## Conclusion
165
165
166
166
By integrating OpenStreetMap data with LLMs, I enabled users to query geospatial
167
167
data using natural language. The system supports filtering, distance
0 commit comments