텍스트 → 쿼리 워크플로

MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

Apoorva Joshi

Senior AI/ML Developer Advocate, MongoDB

텍스트 → 쿼리

텍스트에서 쿼리로 1

MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

텍스트 → 쿼리

텍스트에서 쿼리로 2

MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

텍스트 → 쿼리

텍스트에서 쿼리로 3

MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

텍스트 → 쿼리

텍스트에서 쿼리로 4

MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

텍스트 → 쿼리

텍스트에서 쿼리로 5

MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

텍스트 → 쿼리

텍스트에서 쿼리로

MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

텍스트 → 쿼리: 에이전트 방식

 

쿼리 에이전트

MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

데이터: MongoDB 방식!

 

MongoDB 데이터

MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

구조화 질의어(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()
MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

예시: movies 컬렉션

_id 제목 개봉 연도 출연 장르
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]
... ... ... [...] [...]
MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

단일 필터

query = {"genre": "Romance"}
MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

단일 필터

query = {"genre": "Romance"}
_id 제목 개봉 연도 출연 장르
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]
MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

다중 필터

query = { "$and": [
                    {"year": {"$gte": 1990}},
                    {"year": {"$lt": 2000}}
                  ]
        }
MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

다중 필터

query = { "$and": [
                    {"year": {"$gte": 1990}},
                    {"year": {"$lt": 2000}}
                  ]
        }
_id 제목 개봉 연도 출연 장르
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]
MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

집계 파이프라인

파이프라인

db.<collection>.aggregate([
    {stage-1},
    {stage-2},
    {stage-3},
    {stage-4},
])
MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

다중 연산

query = [




]
MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

다중 연산

query = [

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


]
  • released로 정렬
MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

다중 연산

query = [

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

]
  • released로 정렬
  • 결과 5개 제한
MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

다중 연산

query = [

{ "$sort": { "released": -1 } },
{ "$limit": 5 },
{ "$project": { "title": 1, "_id": 0 } }
]
  • released로 정렬
  • 결과 5개 제한
  • "title" 컬럼만 출력
MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

다중 연산

query = [

{ "$sort": { "released": -1 } },
{ "$limit": 5 },
{ "$project": { "title": 1, "_id": 0 } }
]
  • released로 정렬
  • 결과 5개 제한
  • "title" 컬럼만 출력
제목
The Treasure
Knight of Cups
Sand Castles
Shut In
Dègradè
MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

그룹 집계

_id 제목 개봉 연도 출연 장르
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]
... ... ... [...] [...]
MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

그룹 집계

query = [

{ "$unwind": "$genres" },
{ "$group": { "_id": "$genres", "numMovies": { "$sum": 1 } }},
{ "$match": { "numMovies": { "$gte": 50 } } }
]
MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

그룹 집계

 

장르 개수
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, ...
MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

연습해 봅시다!

MongoDB와 LangGraph로 만드는 Text-to-Query 에이전트

Preparing Video For Download...