Skip to content

vn.train

vn.train 是一个包装函数,允许你训练系统(即位于LLM之上的检索增强层)。你可以通过以下方式调用它:

DDL语句

这些语句让系统了解有哪些表、列和数据类型可用。

vn.train(ddl="CREATE TABLE my_table (id INT, name TEXT)")

文档字符串

这些可以是关于您的数据库、业务或行业的任何文档,这些文档可能是LLM理解用户问题背景所必需的。

vn.train(documentation="Our business defines XYZ as ABC")

SQL语句

系统理解的最有帮助的事情之一是在您的组织中常用的SQL查询。这将帮助系统理解所提出问题的上下文。

vn.train(sql="SELECT col1, col2, col3 FROM my_table")

问题-SQL 对

您还可以使用问题-SQL对来训练系统。这是训练系统最直接的方式,对于系统理解所提问题的上下文最有帮助。

vn.train(
    question="What is the average age of our customers?", 
    sql="SELECT AVG(age) FROM customers"
)

问题-SQL对包含了丰富的嵌入信息,系统可以利用这些信息来理解问题的上下文。当用户倾向于提出具有很多模糊性的问题时,这一点尤其重要。

培训计划

# The information schema query may need some tweaking depending on your database. This is a good starting point.
df_information_schema = vn.run_sql("SELECT * FROM INFORMATION_SCHEMA.COLUMNS")

# This will break up the information schema into bite-sized chunks that can be referenced by the LLM
plan = vn.get_training_plan_generic(df_information_schema)
plan

# If you like the plan, then uncomment this and run it to train
vn.train(plan=plan)

训练计划基本上只是将您的数据库信息模式分解成小块,可以由LLM引用。这是快速用大量数据训练系统的好方法。