LanternVectorStore#

pydantic model llama_index.vector_stores.LanternVectorStore#

Show JSON schema
{
   "title": "LanternVectorStore",
   "description": "Abstract vector store protocol.",
   "type": "object",
   "properties": {
      "stores_text": {
         "title": "Stores Text",
         "default": true,
         "type": "boolean"
      },
      "is_embedding_query": {
         "title": "Is Embedding Query",
         "default": true,
         "type": "boolean"
      },
      "connection_string": {
         "title": "Connection String",
         "type": "string"
      },
      "async_connection_string": {
         "title": "Async Connection String",
         "type": "string"
      },
      "table_name": {
         "title": "Table Name",
         "type": "string"
      },
      "schema_name": {
         "title": "Schema Name",
         "type": "string"
      },
      "embed_dim": {
         "title": "Embed Dim",
         "type": "integer"
      },
      "hybrid_search": {
         "title": "Hybrid Search",
         "type": "boolean"
      },
      "text_search_config": {
         "title": "Text Search Config",
         "type": "string"
      },
      "cache_ok": {
         "title": "Cache Ok",
         "type": "boolean"
      },
      "perform_setup": {
         "title": "Perform Setup",
         "type": "boolean"
      },
      "debug": {
         "title": "Debug",
         "type": "boolean"
      },
      "flat_metadata": {
         "title": "Flat Metadata",
         "default": false,
         "type": "boolean"
      },
      "class_name": {
         "title": "Class Name",
         "type": "string",
         "default": "LanternStore"
      }
   },
   "required": [
      "connection_string",
      "async_connection_string",
      "table_name",
      "schema_name",
      "embed_dim",
      "hybrid_search",
      "text_search_config",
      "cache_ok",
      "perform_setup",
      "debug"
   ]
}

Config
  • schema_extra: function = <function BaseComponent.Config.schema_extra at 0x7ff1e41e53a0>

Fields
  • async_connection_string (str)

  • cache_ok (bool)

  • connection_string (str)

  • debug (bool)

  • embed_dim (int)

  • hybrid_search (bool)

  • perform_setup (bool)

  • schema_name (str)

  • table_name (str)

  • text_search_config (str)

field async_connection_string: str [Required]#
field cache_ok: bool [Required]#
field connection_string: str [Required]#
field debug: bool [Required]#
field embed_dim: int [Required]#
field perform_setup: bool [Required]#
field schema_name: str [Required]#
field table_name: str [Required]#
field text_search_config: str [Required]#
class Select(*entities: _ColumnsClauseArgument[Any])#

Represents a SELECT statement.

The _sql.Select object is normally constructed using the _sql.select() function. See that function for details.

See also

_sql.select()

tutorial_selecting_data - in the 2.0 tutorial

add_columns(*entities: _ColumnsClauseArgument[Any]) Select[Any]#

Return a new _expression.select() construct with the given entities appended to its columns clause.

E.g.:

my_select = my_select.add_columns(table.c.new_column)

The original expressions in the columns clause remain in place. To replace the original expressions with new ones, see the method _expression.Select.with_only_columns().

Parameters

*entities – column, table, or other entity expressions to be added to the columns clause

See also

_expression.Select.with_only_columns() - replaces existing expressions rather than appending.

orm_queryguide_select_multiple_entities - ORM-centric example

column(column: _ColumnsClauseArgument[Any]) Select[Any]#

Return a new _expression.select() construct with the given column expression added to its columns clause.

Deprecated since version 1.4: The _expression.Select.column() method is deprecated and will be removed in a future release. Please use _expression.Select.add_columns()

E.g.:

my_select = my_select.column(table.c.new_column)

See the documentation for _expression.Select.with_only_columns() for guidelines on adding /replacing the columns of a _expression.Select object.

property column_descriptions: Any#

Return a plugin-enabled ‘column descriptions’ structure referring to the columns which are SELECTed by this statement.

This attribute is generally useful when using the ORM, as an extended structure which includes information about mapped entities is returned. The section queryguide_inspection contains more background.

For a Core-only statement, the structure returned by this accessor is derived from the same objects that are returned by the Select.selected_columns accessor, formatted as a list of dictionaries which contain the keys name, type and expr, which indicate the column expressions to be selected:

>>> stmt = select(user_table)
>>> stmt.column_descriptions
[
    {
        'name': 'id',
        'type': Integer(),
        'expr': Column('id', Integer(), ...)},
    {
        'name': 'name',
        'type': String(length=30),
        'expr': Column('name', String(length=30), ...)}
]

Changed in version 1.4.33: The Select.column_descriptions attribute returns a structure for a Core-only set of entities, not just ORM-only entities.

See also

UpdateBase.entity_description - entity information for an insert(), update(), or delete()

queryguide_inspection - ORM background

property columns_clause_froms: List[FromClause]#

Return the set of _expression.FromClause objects implied by the columns clause of this SELECT statement.

New in version 1.4.23.

See also

_sql.Select.froms - “final” FROM list taking the full statement into account

_sql.Select.with_only_columns() - makes use of this collection to set up a new FROM list

correlate(*fromclauses: Union[Literal[None, False], _FromClauseArgument]) Self#

Return a new _expression.Select which will correlate the given FROM clauses to that of an enclosing _expression.Select.

Calling this method turns off the _expression.Select object’s default behavior of “auto-correlation”. Normally, FROM elements which appear in a _expression.Select that encloses this one via its WHERE clause, ORDER BY, HAVING or columns clause will be omitted from this _expression.Select object’s FROM clause. Setting an explicit correlation collection using the _expression.Select.correlate() method provides a fixed list of FROM objects that can potentially take place in this process.

When _expression.Select.correlate() is used to apply specific FROM clauses for correlation, the FROM elements become candidates for correlation regardless of how deeply nested this _expression.Select object is, relative to an enclosing _expression.Select which refers to the same FROM object. This is in contrast to the behavior of “auto-correlation” which only correlates to an immediate enclosing _expression.Select. Multi-level correlation ensures that the link between enclosed and enclosing _expression.Select is always via at least one WHERE/ORDER BY/HAVING/columns clause in order for correlation to take place.

If None is passed, the _expression.Select object will correlate none of its FROM entries, and all will render unconditionally in the local FROM clause.

Parameters

*fromclauses – one or more FromClause or other FROM-compatible construct such as an ORM mapped entity to become part of the correlate collection; alternatively pass a single value None to remove all existing correlations.

See also

_expression.Select.correlate_except()

tutorial_scalar_subquery

correlate_except(*fromclauses: Union[Literal[None, False], _FromClauseArgument]) Self#

Return a new _expression.Select which will omit the given FROM clauses from the auto-correlation process.

Calling _expression.Select.correlate_except() turns off the _expression.Select object’s default behavior of “auto-correlation” for the given FROM elements. An element specified here will unconditionally appear in the FROM list, while all other FROM elements remain subject to normal auto-correlation behaviors.

If None is passed, or no arguments are passed, the _expression.Select object will correlate all of its FROM entries.

Parameters

*fromclauses – a list of one or more _expression.FromClause constructs, or other compatible constructs (i.e. ORM-mapped classes) to become part of the correlate-exception collection.

See also

_expression.Select.correlate()

tutorial_scalar_subquery

distinct(*expr: _ColumnExpressionArgument[Any]) Self#

Return a new _expression.select() construct which will apply DISTINCT to its columns clause.

Parameters

*expr

optional column expressions. When present, the PostgreSQL dialect will render a DISTINCT ON (<expressions>>) construct.

Deprecated since version 1.4: Using *expr in other dialects is deprecated and will raise _exc.CompileError in a future version.

except_(*other: _SelectStatementForCompoundArgument) CompoundSelect#

Return a SQL EXCEPT of this select() construct against the given selectable provided as positional arguments.

Parameters

*other

one or more elements with which to create a UNION.

Changed in version 1.4.28: multiple elements are now accepted.

except_all(*other: _SelectStatementForCompoundArgument) CompoundSelect#

Return a SQL EXCEPT ALL of this select() construct against the given selectables provided as positional arguments.

Parameters

*other

one or more elements with which to create a UNION.

Changed in version 1.4.28: multiple elements are now accepted.

filter(*criteria: _ColumnExpressionArgument[bool]) Self#

A synonym for the _sql.Select.where() method.

filter_by(**kwargs: Any) Self#

apply the given filtering criterion as a WHERE clause to this select.

from_statement(statement: ReturnsRowsRole) ExecutableReturnsRows#

Apply the columns which this Select would select onto another statement.

This operation is plugin-specific and will raise a not supported exception if this _sql.Select does not select from plugin-enabled entities.

The statement is typically either a _expression.text() or _expression.select() construct, and should return the set of columns appropriate to the entities represented by this Select.

See also

orm_queryguide_selecting_text - usage examples in the ORM Querying Guide

property froms: Sequence[FromClause]#

Return the displayed list of _expression.FromClause elements.

Deprecated since version 1.4.23: The _expression.Select.froms attribute is moved to the _expression.Select.get_final_froms() method.

get_children(**kw: Any) Iterable[ClauseElement]#

Return immediate child visitors.HasTraverseInternals elements of this visitors.HasTraverseInternals.

This is used for visit traversal.

**kw may contain flags that change the collection that is returned, for example to return a subset of items in order to cut down on larger traversals, or to return child items from a different context (such as schema-level collections instead of clause-level).

get_final_froms() Sequence[FromClause]#

Compute the final displayed list of _expression.FromClause elements.

This method will run through the full computation required to determine what FROM elements will be displayed in the resulting SELECT statement, including shadowing individual tables with JOIN objects, as well as full computation for ORM use cases including eager loading clauses.

For ORM use, this accessor returns the post compilation list of FROM objects; this collection will include elements such as eagerly loaded tables and joins. The objects will not be ORM enabled and not work as a replacement for the _sql.Select.select_froms() collection; additionally, the method is not well performing for an ORM enabled statement as it will incur the full ORM construction process.

To retrieve the FROM list that’s implied by the “columns” collection passed to the _sql.Select originally, use the _sql.Select.columns_clause_froms accessor.

To select from an alternative set of columns while maintaining the FROM list, use the _sql.Select.with_only_columns() method and pass the :paramref:`_sql.Select.with_only_columns.maintain_column_froms` parameter.

New in version 1.4.23: - the _sql.Select.get_final_froms() method replaces the previous _sql.Select.froms accessor, which is deprecated.

See also

_sql.Select.columns_clause_froms

having(*having: _ColumnExpressionArgument[bool]) Self#

Return a new _expression.select() construct with the given expression added to its HAVING clause, joined to the existing clause via AND, if any.

property inner_columns: _SelectIterable#

An iterator of all _expression.ColumnElement expressions which would be rendered into the columns clause of the resulting SELECT statement.

This method is legacy as of 1.4 and is superseded by the _expression.Select.exported_columns collection.

intersect(*other: _SelectStatementForCompoundArgument) CompoundSelect#

Return a SQL INTERSECT of this select() construct against the given selectables provided as positional arguments.

Parameters
  • *other

    one or more elements with which to create a UNION.

    Changed in version 1.4.28: multiple elements are now accepted.

  • **kwargs – keyword arguments are forwarded to the constructor for the newly created _sql.CompoundSelect object.

intersect_all(*other: _SelectStatementForCompoundArgument) CompoundSelect#

Return a SQL INTERSECT ALL of this select() construct against the given selectables provided as positional arguments.

Parameters
  • *other

    one or more elements with which to create a UNION.

    Changed in version 1.4.28: multiple elements are now accepted.

  • **kwargs – keyword arguments are forwarded to the constructor for the newly created _sql.CompoundSelect object.

is_derived_from(fromclause: Optional[FromClause]) bool#

Return True if this ReturnsRows is ‘derived’ from the given FromClause.

An example would be an Alias of a Table is derived from that Table.

join(target: _JoinTargetArgument, onclause: Optional[_OnClauseArgument] = None, *, isouter: bool = False, full: bool = False) Self#

Create a SQL JOIN against this _expression.Select object’s criterion and apply generatively, returning the newly resulting _expression.Select.

E.g.:

stmt = select(user_table).join(address_table, user_table.c.id == address_table.c.user_id)

The above statement generates SQL similar to:

SELECT user.id, user.name FROM user JOIN address ON user.id = address.user_id

Changed in version 1.4: _expression.Select.join() now creates a _sql.Join object between a _sql.FromClause source that is within the FROM clause of the existing SELECT, and a given target _sql.FromClause, and then adds this _sql.Join to the FROM clause of the newly generated SELECT statement. This is completely reworked from the behavior in 1.3, which would instead create a subquery of the entire _expression.Select and then join that subquery to the target.

This is a backwards incompatible change as the previous behavior was mostly useless, producing an unnamed subquery rejected by most databases in any case. The new behavior is modeled after that of the very successful _orm.Query.join() method in the ORM, in order to support the functionality of _orm.Query being available by using a _sql.Select object with an _orm.Session.

See the notes for this change at change_select_join.

Parameters
  • target – target table to join towards

  • onclause – ON clause of the join. If omitted, an ON clause is generated automatically based on the _schema.ForeignKey linkages between the two tables, if one can be unambiguously determined, otherwise an error is raised.

  • isouter – if True, generate LEFT OUTER join. Same as _expression.Select.outerjoin().

  • full – if True, generate FULL OUTER join.

See also

tutorial_select_join - in the /tutorial/index

orm_queryguide_joins - in the queryguide_toplevel

_expression.Select.join_from()

_expression.Select.outerjoin()

join_from(from_: _FromClauseArgument, target: _JoinTargetArgument, onclause: Optional[_OnClauseArgument] = None, *, isouter: bool = False, full: bool = False) Self#

Create a SQL JOIN against this _expression.Select object’s criterion and apply generatively, returning the newly resulting _expression.Select.

E.g.:

stmt = select(user_table, address_table).join_from(
    user_table, address_table, user_table.c.id == address_table.c.user_id
)

The above statement generates SQL similar to:

SELECT user.id, user.name, address.id, address.email, address.user_id
FROM user JOIN address ON user.id = address.user_id

New in version 1.4.

Parameters
  • from_ – the left side of the join, will be rendered in the FROM clause and is roughly equivalent to using the Select.select_from() method.

  • target – target table to join towards

  • onclause – ON clause of the join.

  • isouter – if True, generate LEFT OUTER join. Same as _expression.Select.outerjoin().

  • full – if True, generate FULL OUTER join.

See also

tutorial_select_join - in the /tutorial/index

orm_queryguide_joins - in the queryguide_toplevel

_expression.Select.join()

outerjoin(target: _JoinTargetArgument, onclause: Optional[_OnClauseArgument] = None, *, full: bool = False) Self#

Create a left outer join.

Parameters are the same as that of _expression.Select.join().

Changed in version 1.4: _expression.Select.outerjoin() now creates a _sql.Join object between a _sql.FromClause source that is within the FROM clause of the existing SELECT, and a given target _sql.FromClause, and then adds this _sql.Join to the FROM clause of the newly generated SELECT statement. This is completely reworked from the behavior in 1.3, which would instead create a subquery of the entire _expression.Select and then join that subquery to the target.

This is a backwards incompatible change as the previous behavior was mostly useless, producing an unnamed subquery rejected by most databases in any case. The new behavior is modeled after that of the very successful _orm.Query.join() method in the ORM, in order to support the functionality of _orm.Query being available by using a _sql.Select object with an _orm.Session.

See the notes for this change at change_select_join.

See also

tutorial_select_join - in the /tutorial/index

orm_queryguide_joins - in the queryguide_toplevel

_expression.Select.join()

outerjoin_from(from_: _FromClauseArgument, target: _JoinTargetArgument, onclause: Optional[_OnClauseArgument] = None, *, full: bool = False) Self#

Create a SQL LEFT OUTER JOIN against this _expression.Select object’s criterion and apply generatively, returning the newly resulting _expression.Select.

Usage is the same as that of _selectable.Select.join_from().

reduce_columns(only_synonyms: bool = True) Select#

Return a new _expression.select() construct with redundantly named, equivalently-valued columns removed from the columns clause.

“Redundant” here means two columns where one refers to the other either based on foreign key, or via a simple equality comparison in the WHERE clause of the statement. The primary purpose of this method is to automatically construct a select statement with all uniquely-named columns, without the need to use table-qualified labels as _expression.Select.set_label_style() does.

When columns are omitted based on foreign key, the referred-to column is the one that’s kept. When columns are omitted based on WHERE equivalence, the first column in the columns clause is the one that’s kept.

Parameters

only_synonyms – when True, limit the removal of columns to those which have the same name as the equivalent. Otherwise, all columns that are equivalent to another are removed.

select_from(*froms: _FromClauseArgument) Self#

Return a new _expression.select() construct with the given FROM expression(s) merged into its list of FROM objects.

E.g.:

table1 = table('t1', column('a'))
table2 = table('t2', column('b'))
s = select(table1.c.a).\
    select_from(
        table1.join(table2, table1.c.a==table2.c.b)
    )

The “from” list is a unique set on the identity of each element, so adding an already present _schema.Table or other selectable will have no effect. Passing a _expression.Join that refers to an already present _schema.Table or other selectable will have the effect of concealing the presence of that selectable as an individual element in the rendered FROM list, instead rendering it into a JOIN clause.

While the typical purpose of _expression.Select.select_from() is to replace the default, derived FROM clause with a join, it can also be called with individual table elements, multiple times if desired, in the case that the FROM clause cannot be fully derived from the columns clause:

select(func.count('*')).select_from(table1)
selected_columns#

A _expression.ColumnCollection representing the columns that this SELECT statement or similar construct returns in its result set, not including _sql.TextClause constructs.

This collection differs from the _expression.FromClause.columns collection of a _expression.FromClause in that the columns within this collection cannot be directly nested inside another SELECT statement; a subquery must be applied first which provides for the necessary parenthesization required by SQL.

For a _expression.select() construct, the collection here is exactly what would be rendered inside the “SELECT” statement, and the _expression.ColumnElement objects are directly present as they were given, e.g.:

col1 = column('q', Integer)
col2 = column('p', Integer)
stmt = select(col1, col2)

Above, stmt.selected_columns would be a collection that contains the col1 and col2 objects directly. For a statement that is against a _schema.Table or other _expression.FromClause, the collection will use the _expression.ColumnElement objects that are in the _expression.FromClause.c collection of the from element.

A use case for the _sql.Select.selected_columns collection is to allow the existing columns to be referenced when adding additional criteria, e.g.:

def filter_on_id(my_select, id):
    return my_select.where(my_select.selected_columns['id'] == id)

stmt = select(MyModel)

# adds "WHERE id=:param" to the statement
stmt = filter_on_id(stmt, 42)

Note

The _sql.Select.selected_columns collection does not include expressions established in the columns clause using the _sql.text() construct; these are silently omitted from the collection. To use plain textual column expressions inside of a _sql.Select construct, use the _sql.literal_column() construct.

New in version 1.4.

self_group(against: Optional[OperatorType] = None) Union[SelectStatementGrouping, Self]#

Apply a ‘grouping’ to this _expression.ClauseElement.

This method is overridden by subclasses to return a “grouping” construct, i.e. parenthesis. In particular it’s used by “binary” expressions to provide a grouping around themselves when placed into a larger expression, as well as by _expression.select() constructs when placed into the FROM clause of another _expression.select(). (Note that subqueries should be normally created using the _expression.Select.alias() method, as many platforms require nested SELECT statements to be named).

As expressions are composed together, the application of self_group() is automatic - end-user code should never need to use this method directly. Note that SQLAlchemy’s clause constructs take operator precedence into account - so parenthesis might not be needed, for example, in an expression like x OR (y AND z) - AND takes precedence over OR.

The base self_group() method of _expression.ClauseElement just returns self.

union(*other: _SelectStatementForCompoundArgument) CompoundSelect#

Return a SQL UNION of this select() construct against the given selectables provided as positional arguments.

Parameters
  • *other

    one or more elements with which to create a UNION.

    Changed in version 1.4.28: multiple elements are now accepted.

  • **kwargs – keyword arguments are forwarded to the constructor for the newly created _sql.CompoundSelect object.

union_all(*other: _SelectStatementForCompoundArgument) CompoundSelect#

Return a SQL UNION ALL of this select() construct against the given selectables provided as positional arguments.

Parameters
  • *other

    one or more elements with which to create a UNION.

    Changed in version 1.4.28: multiple elements are now accepted.

  • **kwargs – keyword arguments are forwarded to the constructor for the newly created _sql.CompoundSelect object.

where(*whereclause: _ColumnExpressionArgument[bool]) Self#

Return a new _expression.select() construct with the given expression added to its WHERE clause, joined to the existing clause via AND, if any.

property whereclause: Optional[ColumnElement[Any]]#

Return the completed WHERE clause for this _expression.Select statement.

This assembles the current collection of WHERE criteria into a single _expression.BooleanClauseList construct.

New in version 1.4.

with_only_columns(*entities: _ColumnsClauseArgument[Any], maintain_column_froms: bool = False, **_Select__kw: Any) Select[Any]#

Return a new _expression.select() construct with its columns clause replaced with the given entities.

By default, this method is exactly equivalent to as if the original _expression.select() had been called with the given entities. E.g. a statement:

s = select(table1.c.a, table1.c.b)
s = s.with_only_columns(table1.c.b)

should be exactly equivalent to:

s = select(table1.c.b)

In this mode of operation, _sql.Select.with_only_columns() will also dynamically alter the FROM clause of the statement if it is not explicitly stated. To maintain the existing set of FROMs including those implied by the current columns clause, add the :paramref:`_sql.Select.with_only_columns.maintain_column_froms` parameter:

s = select(table1.c.a, table2.c.b)
s = s.with_only_columns(table1.c.a, maintain_column_froms=True)

The above parameter performs a transfer of the effective FROMs in the columns collection to the _sql.Select.select_from() method, as though the following were invoked:

s = select(table1.c.a, table2.c.b)
s = s.select_from(table1, table2).with_only_columns(table1.c.a)

The :paramref:`_sql.Select.with_only_columns.maintain_column_froms` parameter makes use of the _sql.Select.columns_clause_froms collection and performs an operation equivalent to the following:

s = select(table1.c.a, table2.c.b)
s = s.select_from(*s.columns_clause_froms).with_only_columns(table1.c.a)
Parameters
  • *entities – column expressions to be used.

  • maintain_column_froms

    boolean parameter that will ensure the FROM list implied from the current columns clause will be transferred to the _sql.Select.select_from() method first.

    New in version 1.4.23.

add(nodes: List[BaseNode]) List[str]#

Add nodes to vector store.

async aquery(query: VectorStoreQuery, **kwargs: Any) VectorStoreQueryResult#

Asynchronously query vector store. NOTE: this is not implemented for all vector stores. If not implemented, it will just call query synchronously.

async async_add(nodes: List[BaseNode], **kwargs: Any) List[str]#

Asynchronously add nodes to vector store. NOTE: this is not implemented for all vector stores. If not implemented, it will just call add synchronously.

classmethod class_name() str#

Get the class name, used as a unique ID in serialization.

This provides a key that makes serialization robust against actual class name changes.

async close() None#
delete(ref_doc_id: str, **delete_kwargs: Any) None#

Delete nodes using with ref_doc_id.

classmethod from_params(host: Optional[str] = None, port: Optional[str] = None, database: Optional[str] = None, user: Optional[str] = None, password: Optional[str] = None, table_name: str = 'llamaindex', schema_name: str = 'public', connection_string: Optional[str] = None, async_connection_string: Optional[str] = None, hybrid_search: bool = False, text_search_config: str = 'english', embed_dim: int = 1536, m: int = 16, ef_construction: int = 128, ef: int = 64, cache_ok: bool = False, perform_setup: bool = True, debug: bool = False) LanternVectorStore#

Return connection string from database parameters.

query(query: VectorStoreQuery, **kwargs: Any) VectorStoreQueryResult#

Query vector store.

property client: Any#

Get client.