Database Tools - SQL and a VectorStore Together
How to chain a SQL lookup into a vector search Fetch a user's row from Postgres, look up the policies that apply to their type, and have an analyst summarize both.
Open in the playground and play with it →
halo
// ============================================================
// Database Tools - SQL and a VectorStore Together
// ============================================================
// LEARN: How to chain a SQL lookup into a vector search
// WHY: Fetch a user's row from Postgres, look up the policies that
// apply to their type, and have an analyst summarize both.
// ============================================================
tool UsersDB : PostgreSQL("postgres://user:pass@localhost:5432/mydb")
tool KnowledgeBase : VectorStore("index-123")
agent Analyst [openai/gpt-4]
equips UsersDB, KnowledgeBase
pipeline AnalyzeUser(userId: String) -> Result:
userId
|> UsersDB.execute(query: "SELECT * FROM users WHERE id = '{{context.input.userId}}'")
|> KnowledgeBase.execute(method: "search", query: "Policies for user type: {{context.current.type}}")
|> Analyst.prompt("Summarize the user profile and relevant policies. User: {{context.data.UsersDB.execute}}, Policies: {{context.current}}")