libSQLRetrieverTool
This component lets you pull information from a libSQL or Turso database and turn it into a tool that can be used by other parts of your Nappai workflow. It’s especially handy when you want to ask a language model to fetch data from a database without writing code yourself.
⚠️ DEPRECATION WARNING
This component is deprecated and will be removed in a future version of Nappai. Please migrate to the recommended alternative components.
How it Works
The libSQLRetrieverTool connects to a libSQL/Turso database using the connection details you provide in Database Info. It then runs the SQL query you write in SQL Query Template. The query must return a column named text; the content of that column is turned into a vector using the Embedding you supply. Finally, the tool is packaged so that other components (like a language model) can ask it to retrieve the most relevant text snippets based on a user’s question.
Inputs
- Database Info: Connection details for the libSQL/Turso database you want to query.
- Embedding: The embedding model or method that will convert the retrieved text into a vector for similarity search.
- Metadata Schema: The schema that describes the structure of the data you’re retrieving, used by the SelfQueryRetriever.
- SQL Query Template: A SQL statement that returns a column named text. You can use
{[input]}
placeholders to insert dynamic values. - Tool Description: A short description of what the tool does, used by the language model to understand its purpose.
- Tool Name: The name you want the tool to have when it appears in the model’s tool list.
Outputs
- Tool: A BaseTool object that can be passed to other components (e.g., a language model) to perform database queries on demand.
Usage Example
-
Set up the component
- Drag the libSQLRetrieverTool onto your canvas.
- Fill in Database Info with your libSQL/Turso credentials.
- Choose an Embedding model (e.g., OpenAI’s text-embedding-ada-002).
- Define the Metadata Schema that matches your database tables.
- Write a SQL Query Template such as:
SELECT text FROM articles WHERE category = '{[category]}' LIMIT 5;
- Provide a clear Tool Description like “Retrieves recent articles about a given category.”
- Name the tool “ArticleFetcher”.
-
Use the tool in a flow
- Connect the output of a user‑input component to the
{[category]}
placeholder in the query template. - Pass the resulting Tool to a language model component that can call it when the user asks for articles on a topic.
- Connect the output of a user‑input component to the
-
Run the workflow
- The model will call the tool, the tool will query the database, embed the results, and return the most relevant text snippets.
Related Components
- SelfQueryRetriever – Builds on top of this tool to let a language model ask questions that automatically trigger database queries.
- Embedding – The component that provides the embedding model used here.
- Database Connector – A more general connector for other database types.
Tips and Best Practices
- Always return a column named
text
; otherwise the tool will not work. - Test your SQL query directly in the database first to ensure it returns the expected results.
- Keep the query simple and limit the number of rows to avoid long response times.
- Use placeholders carefully; they should match the names you use in the input fields.
- If you need to filter by multiple parameters, add more placeholders and provide the corresponding inputs.
Security Considerations
- Store database credentials securely; avoid hard‑coding them in the workflow.
- Restrict the database user’s permissions to only the tables needed for the query.
- Validate any user‑supplied input that gets inserted into the SQL template to prevent injection attacks.
- Monitor query logs for unusual activity and set up alerts if needed.