Робочий процес text-to-query

Агенти Text-to-Query з MongoDB та LangGraph

Apoorva Joshi

Senior AI/ML Developer Advocate, MongoDB

Text-to-query

texttoquery1.jpg

Агенти Text-to-Query з MongoDB та LangGraph

Text-to-query

texttoquery2.jpg

Агенти Text-to-Query з MongoDB та LangGraph

Text-to-query

texttoquery3.jpg

Агенти Text-to-Query з MongoDB та LangGraph

Text-to-query

texttoquery4.jpg

Агенти Text-to-Query з MongoDB та LangGraph

Text-to-query

texttoquery5.jpg

Агенти Text-to-Query з MongoDB та LangGraph

Text-to-query

texttoquery6.jpg

Агенти Text-to-Query з MongoDB та LangGraph

Text-to-query: агентний підхід

 

query_agent.png

Агенти Text-to-Query з MongoDB та LangGraph

Дані: у стилі MongoDB!

 

mongodb_data.png

Агенти Text-to-Query з MongoDB та LangGraph

Structured Query Language (SQL)

Приклад запиту SQL

SELECT *
FROM table
WHERE year>=1950
LIMIT 5

MongoDB Query API

Приклад JSON-подібного вводу

{ "$and": [
              {"year": {"$gte": 1990}},
              {"year": {"$lt": 2000}}
          ]
}

Методи запитів MongoDB

  • .find(), .insert(), .update(), .delete()
Агенти Text-to-Query з MongoDB та LangGraph

Приклад: колекція movies

_id Title Release Year Cast Genres
573a1396f29313caabce3d17 Larks on a String 1990 [Rudolf Hrusènskè, Vlastimil Brodskè] [Comedy, Drama, Romance]
573a1398f29313caabceab72 The Witching of Ben Wagner 1990 [Sam Bottoms, Harriet Hall, Bettina Rae, Justin Gocke] [Family]
... ... ... [...] [...]
Агенти Text-to-Query з MongoDB та LangGraph

Один фільтр

query = {"genre": "Romance"}
Агенти Text-to-Query з MongoDB та LangGraph

Один фільтр

query = {"genre": "Romance"}
_id Title Release Year Cast Genres
573a1390f29313caabcd6377 Wild and Woolly 1917 [Douglas Fairbanks, Eileen Percy, Calvert Carter, Charles Stevens] [Comedy, Western, Romance]
573a1391f29313caabcd70b4 The Four Horsemen of the Apocalypse 1921 [Pomeroy Cannon, Josef Swickard, Bridgetta Clark, Rudolph Valentino] [Drama, Romance, War]
Агенти Text-to-Query з MongoDB та LangGraph

Кілька фільтрів

query = { "$and": [
                    {"year": {"$gte": 1990}},
                    {"year": {"$lt": 2000}}
                  ]
        }
Агенти Text-to-Query з MongoDB та LangGraph

Кілька фільтрів

query = { "$and": [
                    {"year": {"$gte": 1990}},
                    {"year": {"$lt": 2000}}
                  ]
        }
_id Title Release Year Cast Genres
573a1396f29313caabce3d17 Larks on a String 1990 [Rudolf Hrusènskè, Vlastimil Brodskè] [Comedy, Drama, Romance]
573a1398f29313caabceab72 The Witching of Ben Wagner 1990 [Sam Bottoms, Harriet Hall, Bettina Rae, Justin Gocke] [Family]
Агенти Text-to-Query з MongoDB та LangGraph

Конвеєри агрегації

pipeline.png

db.<collection>.aggregate([
    {stage-1},
    {stage-2},
    {stage-3},
    {stage-4},
])
Агенти Text-to-Query з MongoDB та LangGraph

Кілька операцій

query = [




]
Агенти Text-to-Query з MongoDB та LangGraph

Кілька операцій

query = [

{ "$sort": { "released": -1 } },


]
  • Сортування за released
Агенти Text-to-Query з MongoDB та LangGraph

Кілька операцій

query = [

{ "$sort": { "released": -1 } },
{ "$limit": 5 },

]
  • Сортування за released
  • Обмеження до 5 результатів
Агенти Text-to-Query з MongoDB та LangGraph

Кілька операцій

query = [

{ "$sort": { "released": -1 } },
{ "$limit": 5 },
{ "$project": { "title": 1, "_id": 0 } }
]
  • Сортування за released
  • Обмеження до 5 результатів
  • Проєкція стовпця "title"
Агенти Text-to-Query з MongoDB та LangGraph

Кілька операцій

query = [

{ "$sort": { "released": -1 } },
{ "$limit": 5 },
{ "$project": { "title": 1, "_id": 0 } }
]
  • Сортування за released
  • Обмеження до 5 результатів
  • Проєкція стовпця "title"
Title
The Treasure
Knight of Cups
Sand Castles
Shut In
Dègradè
Агенти Text-to-Query з MongoDB та LangGraph

Групові агрегації

_id Title Release Year Cast Genres
573a1396f29313caabce3d17 Larks on a String 1990 [Rudolf Hrusènskè, Vlastimil Brodskè] [Comedy, Drama, Romance]
573a1398f29313caabceab72 The Witching of Ben Wagner 1990 [Sam Bottoms, Harriet Hall, Bettina Rae, Justin Gocke] [Family]
... ... ... [...] [...]
Агенти Text-to-Query з MongoDB та LangGraph

Групові агрегації

query = [

{ "$unwind": "$genres" },
{ "$group": { "_id": "$genres", "numMovies": { "$sum": 1 } }},
{ "$match": { "numMovies": { "$gte": 50 } } }
]
Агенти Text-to-Query з MongoDB та LangGraph

Групові агрегації

 

Genre Count
Drama 12385
Comedy 6532
Romance 3318
Crime 2457
Thriller 2454
... ...

Етапи конвеєра

  • $match, $group, $facet, $geoNear, $lookup, $merge, $search, $sort...

Оператори

  • Порівняння: $eq, $gt, $gte, ...
  • Математичні: $add, $multiply, $divide...
  • Масиви: $push, $reduce, ...
  • Рядки: $toUpper, $toLower, ...
  • Часові: $dateAdd, $dateDiff, ...
Агенти Text-to-Query з MongoDB та LangGraph

Давайте потренуємось!

Агенти Text-to-Query з MongoDB та LangGraph

Preparing Video For Download...