Tutorial: Add vectors¶
First, import the LynseDB client:
And then, Start the server, you can specify the root path directly
Sequentially add vectors¶
create or truncate a collection:
The add_item
API can be used to add vectors to the database one by one, and it is recommended to always submit data within the insert_session
context manager to ensure the highest level of data security:
2024-09-13 10:44:57 - LynseDB - INFO - Saving data...
2024-09-13 10:44:57 - LynseDB - INFO - Writing chunk to storage...
Data persisting: 100%|██████████| 1/1 [00:00<00:00, 264.76chunk/s]
2024-09-13 10:44:57 - LynseDB - INFO - Writing chunk to storage done.
2024-09-13 10:44:57 - LynseDB - INFO - Pre-building the index...
2024-09-13 10:44:57 - LynseDB - INFO - Building an index using the `Flat-IP` index mode...
2024-09-13 10:44:57 - LynseDB - INFO - Index built.
Now we can see what content the id
returns
1
Print collection
to get some information about it
LocalCollectionInstance(
database="my_vec_db",
collection="test_add_vectors",
shape=(1, 128)
)
Add vectors in bulk¶
Now let's try to add vectors in bulk:
Similarly, we use the bulk_add_items
method within the insert_session
context manager to submit all the data at once:
2024-09-13 10:45:14 - LynseDB - INFO - Saving data...
2024-09-13 10:45:14 - LynseDB - INFO - Writing chunk to storage...
Data persisting: 100%|██████████| 1/1 [00:00<00:00, 460.86chunk/s]
2024-09-13 10:45:14 - LynseDB - INFO - Writing chunk to storage done.
2024-09-13 10:45:14 - LynseDB - INFO - Pre-building the index...
2024-09-13 10:45:14 - LynseDB - INFO - Building an index using the `Flat-IP` index mode...
2024-09-13 10:45:14 - LynseDB - INFO - Index built.
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Isn't it simple? At this point, we can check if the shape of the collection
is correct:
LocalCollectionInstance(
database="my_vec_db",
collection="test_min_vec",
shape=(10, 128)
)