Skip to content
··5 phút đọc

Nâng cấp chatbot hiện tại của tôi

Tôi nâng cấp chatbot Sydney để test hybrid search và query structuring của Weaviate — những tính năng tôi cần để mở rộng chatbot tài chính cho hơn 500 công ty.

Cập nhật (2026): Sydney đã tiến xa kể từ thí nghiệm Weaviate này. Sau khi test FAISS, Weaviate, và các lựa chọn khác, tôi chọn Supabase pgvector cho phiên bản production. Sydney giờ chạy trên Claude với streaming responses và tool use. Ý tưởng hybrid search và query structuring bên dưới đã trực tiếp ảnh hưởng đến cách Sydney hoạt động ngày nay.

Hỏi Sydney →


Bài viết gốc từ tháng 5 năm 2024 được giữ nguyên bên dưới cho bối cảnh.

Như đề cập trong bài viết gần nhất, tôi đang làm việc trên Chatbot tài chính tự đánh giá. Vậy tại sao lại đi vòng để cập nhật chatbot hiện tại Sydney? Vài lý do:

  • Test Weaviate vector store end to end:
    • Tôi đang cố dùng Weaviate làm vector store chính cho chatbot tài chính nhưng gặp vấn đề scaling/kích thước bộ nhớ. Cụ thể, chỉ với 10 năm hồ sơ 10K và 10Q gần nhất cho khoảng 20 công ty, kích thước collection Weaviate đã 2GB. Vậy với cách tiếp cận hiện tại, toàn bộ S&P 500 sẽ là collection khoảng 50+ GB. Quá lớn và tốn nhiều tiền để vận hành/duy trì. Nên tôi đang thử các tham số Product Quantization (PQ) khác nhau.
    • Sau khi thử nhiều vector store khác, tôi nghiêng về Weaviate vì khả năng thực hiện hybrid search với metadata filter ở tốc độ nhanh.
    • Khi tôi đang làm PQ cho Weaviate, một câu hỏi tôi có là làm sao deploy Weaviate trong môi trường production, tức Weaviate Cloud hay dùng AWS/Google Cloud? Có khó deploy không? Tốn bao nhiêu tiền?
    • Vì những câu hỏi này, tôi quyết định deploy Weaviate cho chatbot hiện tại Sydney. Cơ bản tôi sẽ thay FAISS bằng Weaviate.
    • Cho phiên bản hiện tại, tôi dùng Weaviate Cloud
  • Triển khai query translation và query structuring, đồng thời đảm bảo output ở dạng Json để có thể sử dụng.
    • Với query translation, mục tiêu là chia câu hỏi đầu vào thành tập hợp các sub-problems hoặc sub-questions cụ thể có thể trả lời độc lập.
    • Với query structuring: tôi rất quan tâm đến việc tạo không chỉ cụm từ tìm kiếm phù hợp cho hybrid search mà còn metadata phù hợp cho filtering.
      • Điều này cực kỳ quan trọng vì tôi muốn chatbot tài chính lọc đúng theo năm, ngành, v.v., khi cần.
  • Cách thực hiện hybrid-search với nhiều filter và trả về không chỉ nội dung mà còn metadata.

Như bạn thấy, tôi cần tất cả những điều trên để hoạt động để tạo chatbot tài chính nên tại sao không thử áp dụng ở quy mô nhỏ hơn nhiều cho chatbot Sydney trước :)

Tôi vui mừng nói rằng bạn có thể thử Sydney ngay. Nó có tất cả các chức năng trên. Bạn có thể thử hỏi câu hỏi như bên dưới và chatbot sẽ trả về câu trả lời liên quan với link đến bài blog cụ thể nơi nó lấy nội dung.

  • Chandler viết gì về Kevin Rudd năm 2020?
  • Kể cho tôi mọi thứ Chandler viết về Ray Dalio từ 2020 đến nay
  • Chandler viết gì về Health Savings Accounts năm 2022?
  • Chandler đã làm gì năm 2015?

Vậy thôi nhé. Tôi cần quay lại làm việc trên chatbot tài chính :P

Nếu bạn đã thử nghiệm với Weaviate hoặc hybrid search với metadata filter, tôi rất muốn nghe điều gì đã hiệu quả với bạn.

Thân mến,

Chandler

Cập nhật tháng 9 2024

Sydney giờ là agent đa tài có thể:

  • Trả lời câu hỏi về các công ty S&P 500 hiện tại, bao gồm những gì họ đã nộp cho SEC trong 10 năm qua.
  • Cung cấp insights từ 15 năm nội dung blog của tôi.

Xem thêm ở đây.

P.S: Bên dưới là ví dụ về loại prompt tôi đang dùng cho query translation và query structuring.

"You are a helpful assistant that generates multiple sub-questions related to an input question. "
             "The current year is 2024."
             "The goal is to break down the input into a set of specific sub-problems / sub-questions that can be answered in isolation. "
             "Each specific sub-question will be used to retrieve relevant content from a vector store, using similarity search with score. "
             "Phrase the wording of the questions appropriately for this purpose.\n"
             "This vector store includes all of the published blog posts from Chandler Nguyen's blog from 2007 to 2024.\n\n"
             "Original question: \{query\}\n\n"
             "Generate the minimum number of sub-questions necessary to answer the original question. "
             "Your response should be formatted as a JSON array of strings, where each string represents a sub-question. "
             "Do not include any additional words, characters, or explanations in the response.\n\n"
             "Example response:\n"
             '[\n'
             '  "sub-question 1",\n'
             '  "sub-question 2"\n'
             ']'
"""You are a helpful assistant that generates a structured query related to an input question.
The goal is to break down the input into a structured query that can be used to retrieve relevant content from a vector store, using similarity search with score.
This vector store includes all of the published blog posts from Chandler Nguyen's blog from 2007 to 2024.
Original question: \{query\}

You must generate a response in JSON format as described below without any additional words or characters:
[
    "content_search": Similarity search query used to apply to the content of the Chandler Nguyen published blog posts to find similar documents related to the sub-question(s). Ensure the content_search query is not too broad or too specific, and strikes a balance between relevance and completeness. \n
    "start_date": optional field, the start date to search for blog posts that are relevant to the sub-question(s) in YYYY-MM-DD format. If the sub-question(s) do not specify a time frame, leave this field blank or set it to the earliest possible date (e.g., 2007-01-01) to cover a broader range. \n
    "end_date": optional field, the end date to search for blog posts that are relevant to the sub-question(s) in YYYY-MM-DD format. If the sub-question(s) do not specify a time frame, leave this field blank or set it to the latest possible date (e.g., 2024-12-31) to cover a broader range. \n
]

If the sub-question(s) include multiple years or a specific time range, generate 1 response for each year or time range, enclosed in separate JSON objects within the outer array.

Example responses:

For an open-ended sub-question without a specific time frame:
Sub-questions: ["What are the key insights Chandler wrote about Health Savings Accounts (HSA)?"]
[
    "content_search": "Chandler Nguyen blog posts about Health Savings Accounts",
    "start_date": "2007-01-01",
    "end_date": "2024-12-31"
]

For a sub-question specifying a year:
Sub-questions: ["What blog posts did Chandler write in 2018?", "Which blog posts written by Chandler in 2018 mention Kevin Rudd?"]
[
    "content_search": "Chandler Nguyen blog posts in 2018",
    "start_date": "2018-01-01",
    "end_date": "2018-12-31"
],
[
    "content_search": "Kevin Rudd mentioned in Chandler Nguyen blog posts in 2018",
    "start_date": "2018-01-01",
    "end_date": "2018-12-31"
]

For a sub-question specifying a time range:
Sub-questions: ["What did Chandler write about Ray Dalio in 2020?", "What did Chandler write about Ray Dalio in 2021?", "What did Chandler write about Ray Dalio in 2022?"]
[
    "content_search": "Chandler Nguyen blog posts about Ray Dalio in 2020",
    "start_date": "2020-01-01",
    "end_date": "2020-12-31"
],
[
    "content_search": "Chandler Nguyen blog posts about Ray Dalio in 2021",
    "start_date": "2021-01-01",
    "end_date": "2021-12-31"
],
[
    "content_search": "Chandler Nguyen blog posts about Ray Dalio in 2022",
    "start_date": "2022-01-01",
    "end_date": "2022-12-31"
]
"""

P.P.S: Tôi biết front end vẫn rất chậm nên có lẽ tôi cần học thêm về phát triển front end.

Đọc tiếp

Hành trình
Kết nối
Ngôn ngữ
Tùy chọn