Skip to main content

create_vector_table

Function create_vector_table 

Source
pub fn create_vector_table(
    conn: &Connection,
    table_name: &str,
    schema: &str,
    vector_column: &str,
    config: VectorConfig,
) -> Result<()>
Expand description

Helper to create a table with a vector column

This creates the table and initializes the vector column in one step.

ยงExample

use azoth::prelude::*;
use azoth_vector::{create_vector_table, VectorConfig};
use rusqlite::Connection;

struct CreateEmbeddingsTable;

impl azoth::Migration for CreateEmbeddingsTable {
    fn version(&self) -> u32 { 2 }
    fn name(&self) -> &str { "create_embeddings_table" }

    fn up(&self, conn: &Connection) -> Result<()> {
        create_vector_table(
            conn,
            "embeddings",
            "id INTEGER PRIMARY KEY, text TEXT, vector BLOB",
            "vector",
            VectorConfig::default(),
        )?;
        Ok(())
    }

    fn down(&self, conn: &Connection) -> Result<()> {
        conn.execute("DROP TABLE embeddings", [])
            .map_err(|e| azoth::AzothError::Projection(e.to_string()))?;
        Ok(())
    }
}