article_icon
article

Enhancing Function Retrieval with Location-Based Filtering

A look into Location-Based Filtering on DeltaV

2024-08-273 min readFetch.ai

When the user sends a message to DeltaV, it's very important to find agents that are relevant to the user's query, or objective. We achieve this using Elasticsearch's vector database. We now introduced a novel feature that intelligently filters search results based on location. This ensures that when users search for functions or services, they receive the most relevant results.

The Need for Location Filtering

Imagine you're searching for an agent function that depends heavily on location, like finding a nearby restaurant. A standard query might not always return the most relevant results, especially if it doesn't consider your proximity to the services in question. Even if it eventually does find relevant results, it might not be efficient, as it would still need to consider for the search a lot of irrelevant candidates (such as restaurants from other parts of the world). This is where our location filter becomes useful.

How It Works

We integrate a location filtering mechanism with Elasticsearch, utilising Large Language Models (LLMs) to determine when and how to apply this filter. Here's an overview of the process:

Step 1: Deciding If Location Filtering Is Necessary

The first challenge is determining whether a user query actually requires a location filter. Not every query is location-sensitive, so we would miss potentially relevant candidates if we applied a filter unnecessarily. To address this, we use an LLM to analyse the query. The LLM assesses the user's intent and context to decide if location should be a factor in retrieving relevant functions.

Step 2: Extracting Location Information

If the LLM determines that location is important, the next step is extracting the relevant geographical data from the user's query or their associated context. Here, with context we mean whatever additional data DeltaV is provided about the user: for example, it might have the user's coordinates if they consented to share their current location. Also in this step we use an LLM, with the task to extract latitude and longitude coordinates from either the user query or the given context. An interesting scenario arises when the user specifies a location in their query that differs from their current location, for example, "Find a vegetarian restaurant in Cambridge". In such cases, the right thing to do is to filter results based on the location mentioned (Cambridge) rather than where the user is physically located. That's where the LLM's strong contextual understanding is particularly useful.

Step 3: Applying the GeoFilter

Using the extracted coordinates, the system generates a geofilter for Elasticsearch, to narrows down the search results to only include functions that are geographically relevant to the user.

The Power of LLMs in Enhancing Search Relevance

The innovation in our approach lies in leveraging LLMs to interpret and adapt to the nuances of user queries. By intelligently deciding when and how to apply a location filter, our system ensures that Elasticsearch returns only the most relevant results. This not only improves search efficiency but also enhances user satisfaction by delivering agents' functions that are both contextually and geographically appropriate.

Try It Out Now

You can try now this new location-based filtering feature by selecting the 'Next Generation' personality in DeltaV. To support this feature, the Functions API now allows to specify a location for your functions. For example, if you have an existing function hosted on Agentverse and want to update it with location data, here’s how you can do it using the Functions API:

code-icon
code-icon
import requests

# First, we'll retrieve the function's current information
id = "your-function-id"
response = requests.get(f"https://agentverse.ai/v1beta1/functions/{id}", headers={
    "Authorization": "bearer your-agentverse-api-key",
    "Content-Type": "application/json",
})
func = response.json()

# Then, we'll add the function's location
func["metadata_properties"] = {
    "geo_location": {
        "location": {"lat": 52.205338, "lon": 0.121817}
    }
}

# Finally, we'll update the function with the location information
response = requests.put(f"https://agentverse.ai/v1beta1/functions/{id}/", json=func, headers={
    "Authorization": "bearer your-agentverse-api-key",
    "Content-Type": "application/json",
})

For more details, check out the full documentation here.

Future Directions

As this is a new feature, not many functions have location information populated yet. The utility of location filtering will significantly improve as more functions are updated with location data.

As we continue to refine functions retrieval, our focus will be on further improving the accuracy of the results returned from the vector database. This is just a small piece of a broader effort to integrate more advanced AI capabilities into our product, making DeltaV even more responsive to user needs.


More from Fetch