💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Add ability to index database expressions, closes #1049
davidmezzetti2f2bd50027a7
diff --git a/docs/embeddings/configuration/database.md b/docs/embeddings/configuration/database.mdindex 6d689bd7..5b8e9671 100644--- a/docs/embeddings/configuration/database.md+++ b/docs/embeddings/configuration/database.md@@ -50,14 +50,27 @@ Object encoding options are:functions: list```-List of functions with user-defined SQL functions, only used when [content](#content) is enabled. Each list element must be one of the following:+List of functions with user-defined SQL functions. Each list element must be one of the following:- function- callable object-- dict with fields for name, argcount and function+- dict with fields for name, argcount, function and deterministic[An example can be found here](../../query#custom-sql-functions).+## expressions+```yaml+expressions: list+```++List of expression shortcuts. Each list element must be a dict with the following fields.++- `name`: name of the expression+- `expression`: SQL expression, defaults to `name` when empty+- `index`: if this expression should have a database index, defaults to False when not provided++The expression can be a json data column, sql function or anything that can be run as a SQL snippet.+## query```yamlquery:diff --git a/docs/embeddings/query.md b/docs/embeddings/query.mdindex 425d476c..fcbc82d8 100644--- a/docs/embeddings/query.md+++ b/docs/embeddings/query.md@@ -169,6 +169,24 @@ LIMIT 1""")```+## Expressions++Expression shortcuts expand into more complex SQL snippets. This is useful for making SQL queries more concise. Indexing is also available on expressions as a performance improvement.++The following example indexes a json extraction field (`filepath`) and the length of each field.++```python+# Create embeddings index+embeddings = Embeddings(path="sentence-transformers/nli-mpnet-base-v2",+ content=True,+ expressions=[+ {"name": "filepath", "index": True},+ {"name": "textlength", "expression": "length(text)", "index": True}+ ])++embeddings.search("SELECT textlength, filepath FROM txtai LIMIT 1")+```+## Query translationNatural language queries with filters can be converted to txtai-compatible SQL statements with query translation. For example: