Skip to content

Commit ea5fa31

Browse files
author
nightcityblade
committed
docs: add FloatVector overview example
1 parent 7aba9a7 commit ea5fa31

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

docs/overview.rst

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ Extension types
374374
---------------
375375

376376
In the :ref:`example SQLAlchemy table definition <table-definition>` above, we
377-
are making use of the two extension data types that the CrateDB SQLAlchemy
378-
dialect provides.
377+
are making use of extension data types provided by the CrateDB SQLAlchemy
378+
dialect.
379379

380380
.. SEEALSO::
381381

@@ -459,6 +459,35 @@ The resulting object will look like this:
459459
change, the :ref:`UPDATE <crate-reference:dml-updating-data>` statement
460460
sent to CrateDB will include all of the ``ObjectArray`` data.
461461

462+
.. _floatvector:
463+
464+
``FloatVector``
465+
...............
466+
467+
Use ``FloatVector`` to store fixed-length floating-point vectors, such as
468+
embeddings used for similarity search. Pass the vector dimension to the type
469+
when defining the column:
470+
471+
>>> from sqlalchemy_cratedb import FloatVector, knn_match
472+
473+
>>> class SearchIndex(Base):
474+
... __tablename__ = 'search_index'
475+
... name = sa.Column(sa.String, primary_key=True)
476+
... embedding = sa.Column(FloatVector(3))
477+
478+
Values can be supplied as lists of floating-point numbers. To find nearby
479+
vectors, use ``knn_match`` in a query:
480+
481+
>>> item = SearchIndex(name='example', embedding=[1.0, 2.0, 3.0])
482+
>>> session.add(item)
483+
>>> session.commit()
484+
>>> query = session.query(SearchIndex.name).filter(
485+
... knn_match(SearchIndex.embedding, [1.0, 2.0, 2.9], 10)
486+
... )
487+
488+
See the :doc:`vector type guide <working-with-types>` for a complete example,
489+
including storing and retrieving vectors.
490+
462491
.. _geopoint:
463492
.. _geoshape:
464493

0 commit comments

Comments
 (0)