当前位置: 首页 > article >正文

Elasticsearch:智能搜索 - AI builder 及 skills

想象一下我们如何搜索如下的一个问题Find a home within 10 miles of Miami, Florida that has 2 bedrooms, 2 bathrooms, central air, and tile floors, with a budget up to $300,000.这类问题存在于很多的电子商务网站搜索中。它也是一种非常实用的搜索方式之一。那么要实现这样的搜索方式我们有如下的几种方式来实现使用 Python 代码实现工具并让 LLM 来进行调用。我们需要调用 LLM 来提取我们搜索的参数。为了精准搜索我们可以使用 template 来下继续搜索。详细的情况可以参考文章 “统一 Elastic 向量数据库与 LLM 功能实现智能查询”我们可以为这个搜索用 Python 创建一个定制的 MCP 服务器然后在客户端里进行调用。我们可以参考文章 “Elasticsearch智能搜索的 MCP”我们使用 AI Builder 及 Workflow 来实现。在 workflow 里实现类似于在 DSL 中的模版搜索从而达到精确搜索的目的。详细的使用说明请参考文章 “Elasticsearch智能搜索 - AI Builder 及 Workflow”。我们使用 AI BuilderWorkflow 及 Skills 来共同完成。我们使用 geocoding workflow 来完成地理位置的获取详细的实现请参阅文章 “Elasticsearch智能搜索 - AI builderworkflow 及 skills”。在如上的四种种方案里第四种方案的实现最为简捷因为它不需要另外单独的编程。我们只需要在 Kibana 里创建 agent 及 workflow 来完成即可。维护起来也非常简单直接。那么我们有没有更为方便的方法呢答案是肯定的。在即将推出的 Elastic Stack 9.4 中目前在 Elastic Serverless cloud 中可用我们可以使用 skill 来更进一步简化的目的。在第四中方案里我们也使用了 workflow 来完成 geocoding 的工作。我们是否可以直接省去这个环节在 skill 里完成呢答案是肯定的。我们下面来展示是如何完成的。步骤一写入数据我们需要按照文章 “Elasticsearch智能搜索的 MCP” 写入文档到 Elasticsearch 中。步骤二创建 property_search_skills配置IDproperty_search_skillsNameProperty search skillsDescription- Invoke python script to do geocoding - Construct Elasticsearch using DSL search template.Instructions- Used to do the geocoding based the queries - How to construct DSL search template to search the properties indexFilesFile nameproperty_search_skillFolder path./Content--- name: Property Search Skills description: Skills related to property search functionality, including geocoding and location-based queries. --- # Property Search Skills This document outlines the skills and tools used for implementing property search functionality, particularly focusing on geocoding and location-based queries. ## Geocoding Tool The geocoding tool is designed to convert addresses into geographic coordinates (latitude and longitude) using the Google Maps Geocoding API. This allows for location-based searches and queries in property search applications. The API to be used is the Google Maps Geocoding API, which requires an API key for authentication. ### Environment Variables To use the geocoding tool, the following environment variables need to be set: - GOOGLE_MAPS_API_KEY: Your Google Maps API key for accessing the Geocoding API. **geocode_tool.py is the script that implements the geocoding functionality. It takes an address as input and returns the corresponding latitude and longitude coordinates. The results can be stored in Elasticsearch for further querying and analysis in property search applications.** import os import sys import json import argparse import requests GEOCODE_URL https://maps.googleapis.com/maps/api/geocode/json def geocode(address: str, api_key: str) - dict: params { address: address, key: api_key } resp requests.get(GEOCODE_URL, paramsparams, timeout10) resp.raise_for_status() data resp.json() if data.get(status) ! OK: return { success: False, error: data.get(status), raw: data } result data[results][0] location result[geometry][location] return { success: True, formatted_address: result[formatted_address], location: { lat: location[lat], lon: location[lng] # Google - Elasticsearch format }, place_id: result.get(place_id), types: result.get(types) } def main(): parser argparse.ArgumentParser(descriptionGeocode an address) parser.add_argument(--address, helpAddress to geocode) args parser.parse_args() try: # Determine input source (stdin takes priority) if not sys.stdin.isatty(): payload json.load(sys.stdin) address payload.get(address) else: address args.address if not address: raise ValueError(Missing address (provide via --address or stdin JSON)) api_key Your Google API Key # api_key os.environ.get(GOOGLE_API_KEY) # if not api_key: # raise ValueError(Missing GOOGLE_API_KEY environment variable) result geocode(address, api_key) print(json.dumps(result)) sys.exit(0 if result[success] else 1) except Exception as e: print(json.dumps({ success: False, error: str(e) })) sys.exit(1) if __name__ __main__: main() ### Usage To run the geocoding tool, use the following command in your terminal: bash python geocode_tool.py --address 1600 Amphitheatre Parkway, Mountain View, CA This command will geocode the provided address and return the corresponding latitude and longitude coordinates. The results can then be stored in Elasticsearch for further querying and analysis in property search applications. # DSL search templates In addition to geocoding, property search applications often require the ability to perform complex queries on the indexed property data. This can be achieved using Elasticsearchs Domain Specific Language (DSL) for searching and filtering data based on various criteria such as location, price range, property type, etc. The details for implementing a search template can be found at https://www.elastic.co/docs/solutions/search/search-templates. For our search template, we need to use the following search template to do the DSL search: { _source: false, size: 5, fields: [title, tax, maintenance_fee, bathrooms, bedrooms, square_footage, home_price, property_features], retriever: { standard: { query: { semantic: { field: body_content_semantic_text, query: {{query}} } }, filter: { bool: { must: [ {{#distance}}{ geo_distance: { distance: {{distance}}, location: { lat: {{latitude}}, lon: {{longitude}} } } }{{/distance}} {{#bedrooms}}{{#distance}},{{/distance}}{ range: { bedrooms: { gte: {{bedrooms}} } } }{{/bedrooms}} {{#bathrooms}}{{#distance}}{{^bedrooms}},{{/bedrooms}}{{/distance}}{{#bedrooms}},{{/bedrooms}}{ range: { bathrooms: { gte: {{bathrooms}} } } }{{/bathrooms}} {{#tax}}{{#distance}}{{^bedrooms}}{{^bathrooms}},{{/bathrooms}}{{/bedrooms}}{{/distance}}{{#bedrooms}}{{^bathrooms}},{{/bathrooms}}{{/bedrooms}}{{#bathrooms}},{{/bathrooms}}{ range: { tax: { lte: {{tax}} } } }{{/tax}} {{#maintenance}}{{#distance}}{{^bedrooms}}{{^bathrooms}}{{^tax}},{{/tax}}{{/bathrooms}}{{/bedrooms}}{{/distance}}{{#bedrooms}}{{^bathrooms}}{{^tax}},{{/tax}}{{/bathrooms}}{{/bedrooms}}{{#bathrooms}}{{^tax}},{{/tax}}{{/bathrooms}}{{#tax}},{{/tax}}{ range: { maintenance_fee: { lte: {{maintenance}} } } }{{/maintenance}} {{#square_footage_max}}{{#distance}}{{^bedrooms}}{{^bathrooms}}{{^tax}}{{^maintenance}},{{/maintenance}}{{/tax}}{{/bathrooms}}{{/bedrooms}}{{/distance}}{{#bedrooms}}{{^bathrooms}}{{^tax}}{{^maintenance}},{{/maintenance}}{{/tax}}{{/bathrooms}}{{/bedrooms}}{{#bathrooms}}{{^tax}}{{^maintenance}},{{/maintenance}}{{/tax}}{{/bathrooms}}{{#tax}}{{^maintenance}},{{/maintenance}}{{/tax}}{{#maintenance}},{{/maintenance}}{ range: { square_footage: { gte: {{#square_footage_min}}{{square_footage_min}}{{/square_footage_min}}{{^square_footage_min}}0{{/square_footage_min}}, lte: {{square_footage_max}} } } }{{/square_footage_max}} {{#home_price_max}}{{#distance}}{{^bedrooms}}{{^bathrooms}}{{^tax}}{{^maintenance}}{{^square_footage}},{{/square_footage}}{{/maintenance}}{{/tax}}{{/bathrooms}}{{/bedrooms}}{{/distance}}{{#bedrooms}}{{^bathrooms}}{{^tax}}{{^maintenance}}{{^square_footage}},{{/square_footage}}{{/maintenance}}{{/tax}}{{/bathrooms}}{{/bedrooms}}{{#bathrooms}}{{^tax}}{{^maintenance}}{{^square_footage}},{{/square_footage}}{{/maintenance}}{{/tax}}{{/bathrooms}}{{#tax}}{{^maintenance}}{{^square_footage}},{{/square_footage}}{{/maintenance}}{{/tax}}{{#maintenance}}{{^square_footage}},{{/square_footage}}{{/maintenance}}{{#square_footage}},{{/square_footage}}{ range: { home_price: { gte: {{#home_price_min}}{{home_price_min}}{{/home_price_min}}{{^home_price_min}}0{{/home_price_min}}, lte: {{home_price_max}} } } }{{/home_price_max}} {{#feature}},{ bool: { should: [ { match: { property_features: { query: {{feature}}, operator: or } } } ], minimum_should_match: 1 } }{{/feature}} ] } } } } } We need to use properties index to do the search. **please do see the range searches for bedrooms and bathrooms“. We want to have bigger or equal matches. For the price, we need to have equal or smaller matches注请在上面的代码中添加自己的 api_key Your Google API Key。我们保存好上面的 skill 配置。步骤三创建 property_search_skill agent我们按照如的步骤来创建 agent配置IDproperty_search_skillCustom InstructionsThis agent is used to search for properties: # Step 1: You are an information extraction assistant. Extract real estate search parameters from the user query. Parameter descriptions: - bathrooms: Number of bathrooms - bedrooms: Number of bedrooms - tax: Real estate tax amount - maintenance: Maintenance fee amount - square_footage_min: Minimum property square footage. If only a max square footage is provided, set this to 0. Otherwise set this to the minimum square footage specified by the user. - square_footage_max: Maximum property square footage - home_price_min: Minimum home price. If only a max home price is provided, set this to 0. Otherwise set this to the minimum home price specified by the user. - home_price_max: Maximum home price - property_features: Home features such as AC, pool, updated kitchens, etc should be listed as a single string. - location: City, state, or full address if present. Rules: - Only include parameters explicitly mentioned. - property_features must be a single space-separated string. - Return ONLY a JSON object (not a string, no quotes, no extra text, no explanations). - Do not include explanations. Example JSON: { query: Find a home within 10 miles of Miami, Florida that has 2 bedrooms, 2 bathrooms, central air, and tile floors, with a budget up to $300,000. bathrooms: 2, bedrooms: 2, home_price_min: 0, home_price_max: 300000, property_features: central air tile floors, location: Miami, Florida } # Step 2: - Use the above constructed JSON format, and do a DSL template search. If you need to convert it to ES|QL queries, please do follow exactly the DSL template search ranges: 1. bathrooms is bigger or equal to the extracted one 2. bedrooms is bigger or equal to the extracted one 3. home_price is smaller or equal to the extracted one (home_price_max) - Before you do the searches, please DO refer to the requirements specified by the property search skills/property_search_skill.md. - Please print out the search template used for search, and then print out the top **4 results** for viewing.Display nameProperty search skillsDisplay descriptionSearch for property添加 skills我们把创建的 skill 添加到我们创建的 agent 中。测试我们还是按照之前的测试用例来进行测试Find a home within 10 miles of Miami, Florida that has 2 bedrooms, 2 bathrooms, central air, and tile floors, with a budget up to $300,000.我们再以第二个例子来做展示Find a home within 10 miles of DeBary, Florida with 5 bedrooms, at least 2 bathrooms, central air, and a garage, with a budget up to $600,000.结论在这个例子里我们看到了 skill 的强大之处。我们甚至省去了繁琐的代码及 workflow 的创建。我们只使用 skill 即可。这些 skill 只有在需要的时候才会装载。非常省内存。祝大家学习愉快

相关文章:

Elasticsearch:智能搜索 - AI builder 及 skills

想象一下,我们如何搜索如下的一个问题: Find a home within 10 miles of Miami, Florida that has 2 bedrooms, 2 bathrooms, central air, and tile floors, with a budget up to $300,000. 这类问题存在于很多的电子商务网站搜索中。它也是一种非常实…...

使用Hugging Face Spaces构建交互式图像数据集可视化工具

1. 项目概述在计算机视觉领域,数据可视化是理解数据集特征的关键第一步。Hugging Face Spaces(简称HF Space)提供了一个绝佳的平台,让开发者能够快速构建和分享交互式的机器学习应用。这个项目将带你从零开始,创建一个…...

Chem-R框架:AI化学推理的三阶段训练与性能突破

1. Chem-R框架的设计背景与核心挑战化学推理作为AI在科学领域最具挑战性的应用场景之一,其复杂性主要体现在三个方面:首先,分子结构和化学反应涉及高维度的组合空间,一个简单的有机分子就可能存在10^60种可能的异构体;…...

BhashaBench V1:印度多领域AI评估基准的技术解析

1. BhashaBench V1:印度多领域知识评估基准的技术解析与实践价值在人工智能快速发展的今天,大型语言模型(LLM)的评估已成为衡量AI系统实际应用能力的关键环节。BhashaBench V1作为针对印度本土知识系统的专业评估框架,…...

Audiveris终极指南:让纸质乐谱秒变数字音乐的免费神器

Audiveris终极指南:让纸质乐谱秒变数字音乐的免费神器 【免费下载链接】audiveris Latest generation of Audiveris OMR engine 项目地址: https://gitcode.com/gh_mirrors/au/audiveris 你是否曾面对堆积如山的纸质乐谱,渴望将它们一键转化为可编…...

DLSS Swapper:3分钟掌握游戏性能调校神器,让显卡发挥200%潜力

DLSS Swapper:3分钟掌握游戏性能调校神器,让显卡发挥200%潜力 【免费下载链接】dlss-swapper 项目地址: https://gitcode.com/GitHub_Trending/dl/dlss-swapper 你是否遇到过这样的困扰:新买的RTX 40系列显卡,却在某些游戏…...

卫生间沉箱回填,这3个关键点很少人告诉你

上个月去一个别墅工地巡检,正好赶上卫生间沉箱回填。工人正往坑里倒碎砖头、水泥块,我当场就叫停了。项目经理还跟我说“没事,大家都这么干”。我说,你们这么干,以后漏水了谁负责?沉箱回填这事儿&#xff0…...

别墅装修,找监理不是花冤枉钱,但很多人都没找对

前两天帮一个朋友去他正在装修的别墅工地看了一圈。他当时正跟施工方因为一个墙面的平整度问题僵持不下。施工方坚持说没问题,标准之内;他自己看着总觉得别扭,又说不出个所以然。他问我,要不要现在临时找个监理来评评理。说实话&a…...

Docker Desktop已不适用边缘场景?3大被低估的WASM容器运行时替代方案对比实测(含启动耗时、内存驻留、TEE支持度数据)

更多请点击: https://intelliparadigm.com 第一章:Docker WASM 边缘计算部署指南 实战案例 WebAssembly(WASM)正迅速成为边缘计算场景中轻量、安全、跨平台执行逻辑的核心载体,而 Docker 官方自 2023 年起通过 docker…...

还不会 CSS 选择器?超详细基础讲解

CSS简称为样式表,是用于增强或控制网页样式,并允许将样式信息与网页内容分离的一种标记性语言。一、三种CSS引入方法1.行内式:行内样式是各种引入CSS最直接的一种,也叫内联样式。行内样式就是通过直接设置各个元素的style属性&…...

2026最强全能 AI Agent:Codex 零基础完整实战教程(基于 GPT-5.5 与 Image-2 模型)

Codex 被誉为2026年最值得上手的 AI 工具,它不仅是一个编程 Agent,更是一个几乎可以替换掉任何对话工具的全能 AI。配合高性价比的定价机制和充足的 Token 额度,只要你能想到的场景,它都能帮你自动化完成。 本文将带你从零开始&a…...

IVFFlat(Inverted File with Flat Storage)索引算法

IVFFlat 索引算法介绍 概述 IVFFlat(Inverted File with Flat Storage)是IVF算法的一个变种,它在IVF的基础上保持了原始向量的精确存储。与IVFADC(使用量化压缩)不同,IVFFlat在每个聚类中完整存储原始向量&…...

N-氨基甲酰天冬氨酸的SMILES表示与分子设计

1. N-氨基甲酰天冬氨酸的分子结构与生物意义解析 N-氨基甲酰天冬氨酸(N-carbamoylaspartate)是一种具有重要生物学意义的代谢中间体。作为天冬氨酸的衍生物,它在嘧啶核苷酸生物合成途径中扮演关键角色。这个分子最显著的结构特征是在天冬氨酸…...

【2024最严AI代码沙箱标准】:NIST SP 800-190合规配置清单+实测性能损耗<2.3%

更多请点击: https://intelliparadigm.com 第一章:【2024最严AI代码沙箱标准】核心要义与NIST SP 800-190合规性全景解读 AI代码沙箱已从可选实践跃升为强制性安全基线。2024年发布的《AI代码运行环境最小保障规范》(ACRE-2024)明…...

Kafka-King:解决企业级Kafka运维痛点的现代化桌面客户端

Kafka-King:解决企业级Kafka运维痛点的现代化桌面客户端 【免费下载链接】Kafka-King A modern and practical kafka GUI client 💕🎉Kafka-King 是一款现代化、实用的 Kafka GUI 客户端,旨在通过直观的桌面界面简化 Apache Kafka…...

【20年嵌入式老兵亲授】:C语言裸机编程在工业边缘节点中规避内存泄漏与时序抖动的7个硬核技巧

更多请点击: https://intelliparadigm.com 第一章:裸机环境下的C语言编程本质与工业边缘节点特殊约束 在工业边缘计算场景中,裸机(Bare-metal)C编程并非仅是“不带操作系统的C”,而是对硬件时序、内存拓扑…...

Wox终极指南:如何用跨平台启动器提升10倍工作效率?

Wox终极指南:如何用跨平台启动器提升10倍工作效率? 【免费下载链接】Wox A cross-platform launcher that simply works 项目地址: https://gitcode.com/gh_mirrors/wo/Wox 你是否厌倦了在Windows、Mac或Linux系统中反复点击菜单寻找应用&#xf…...

4GB显存也能玩转SDXL?Fooocus低配置AI绘图终极指南

4GB显存也能玩转SDXL?Fooocus低配置AI绘图终极指南 【免费下载链接】Fooocus Focus on prompting and generating 项目地址: https://gitcode.com/GitHub_Trending/fo/Fooocus 你是否曾因电脑配置不足而错失AI绘图创作的乐趣?当大多数AI绘画工具动…...

CSS浮动布局的性能优化_减少不必要的清除浮动代码

clear: both 会拖慢重排,因浏览器需回溯所有浮动元素定位以确定清除点,打断渲染流水线并强制重排;现代推荐用 display: flow-root 创建BFC自动包裹浮动,更轻量安全。为什么 clear: both 会拖慢重排?浏览器在遇到 clear…...

【仅限首批200位农业数字化工程师】:Python多源农业数据融合私密工作坊——手把手复现国家数字乡村试点县融合引擎(含原始遥感+LoRa+农机CAN总线数据集)

更多请点击: https://intelliparadigm.com 第一章:Python农业物联网多源数据融合概述 在智慧农业实践中,传感器网络、无人机遥感、气象站、土壤检测仪及边缘网关等设备持续产生异构、时序、空间分布不均的多源数据。Python凭借其丰富的科学计…...

作为一名在读博士生,我在日常是如何与AI协作的?

前言:当同事,不当工具 我是一名人工智能方向的在读博士生,大概在 ChatGPT 出来以后还是 GPT-3.5 的时候就比较重度使用 AI 以及 AI 工具了。几年下来,AI 已经渗透到我工作和学习很多环节,有一些心得想分享一下~ 当同…...

基于声网RTC与OpenAI Realtime API构建低延迟语音AI助手

1. 项目概述与核心价值 最近在折腾实时语音交互应用,特别是想给产品加上类似ChatGPT那种能听会说、还能实时思考的“智能体”能力。市面上现成的方案要么太贵,要么延迟高得没法用,要么就是集成起来一堆坑。直到我发现了声网开源的 AgoraIO/…...

论文降重新革命:书匠策AI,解锁学术纯净新境界

在学术的广阔天地里,论文写作是每位学者必经的修行之路。从选题构思到文献综述,从实验设计到数据分析,每一步都凝聚着学者的心血与智慧。然而,当论文初稿完成,降重和去除AIGC(人工智能生成内容)…...

Flux2-Klein-9B-True-V2惊艳效果:机械结构爆炸图+剖面标注+材质区分渲染

Flux2-Klein-9B-True-V2惊艳效果:机械结构爆炸图剖面标注材质区分渲染 1. 模型能力展示 1.1 机械结构爆炸图生成 Flux2-Klein-9B-True-V2在机械设计领域展现出惊人能力,能够生成专业级的爆炸分解图。输入简单描述如"机械手表内部结构爆炸图"…...

Python 玩转摄像头:MediaPipe 手势追踪贪吃蛇游戏(含完整环境配置教程)

本文将带你从零开始搭建一个 Python 多功能项目 Project2(https://github.com/WLHSDXN/Project2)。 无论你是想学习计算机视觉、自动化脚本,还是 Web 爬虫 邮件通知,这个项目都能给你完整的实践参考。 一、整体项目结构 Project2…...

避开Halcon点云分析第一个坑:手把手教你用`visualize_object_model_3d`正确显示与交互

Halcon 3D点云可视化实战:从参数解析到交互控制 第一次接触Halcon的3D点云分析时,我盯着屏幕上那团漆黑的点云数据手足无措——明明导入了数据,却不知道如何旋转查看不同角度,更别说测量特定高度了。visualize_object_model_3d这个…...

暗黑破坏神2存档编辑器:d2s-editor完全指南

暗黑破坏神2存档编辑器:d2s-editor完全指南 【免费下载链接】d2s-editor 项目地址: https://gitcode.com/gh_mirrors/d2/d2s-editor 还在为暗黑破坏神2漫长的刷装备过程感到疲惫吗?想要快速体验不同职业build却不想从头练级?d2s-edit…...

计算机视觉算法优化方法

计算机视觉算法优化方法:提升效率与精度的关键路径 计算机视觉作为人工智能的核心领域之一,广泛应用于自动驾驶、医疗影像、安防监控等场景。随着任务复杂度的提升,算法的计算效率、精度和泛化能力面临巨大挑战。如何优化算法成为研究者关注…...

百度Agent岗一面:你知道哪些更复杂的 RAG 范式?

👔面试官:你了解哪些更复杂的 RAG 范式?除了最基本的检索加生成,还有什么更高级的玩法? 🙋‍♂️我:呃,我觉得 Advanced RAG 就是最复杂的了吧,加个 Rerank 和 Query 改…...

JavaScript 需求稳定,多类证书助力职业发展,招聘看重实践与证书结合!

考取这些 JavaScript 证书,证明热门技能!招聘看重,多证书可选助力职业发展考取这些 JavaScript 证书,能证明你掌握了全球最常用编程语言的热门技能。JavaScript 一直是网页开发领域最受欢迎的编程语言之一,短期内这种情…...