INNER CODE UNIT · TypeScript

createVectorTable

margelo/react-native-nitro-sqlite · packages/react-native-nitro-sqlite-vec/src/index.ts:71

export function createVectorTable(
  db: NitroSQLiteConnection,
  table: string,
  options: CreateVectorTableOptions,
): void {
  const column = options.column ?? 'embedding'
  const type = options.type ?? 'float'
  const metric = options.distanceMetric
  const metricClause = metric ? ` distance_metric=${metric}` : ''
  db.execute(
    `CREATE VIRTUAL TABLE IF NOT EXISTS ${table} USING vec0(${column} ${type}[${options.dimensions}]${metricClause});`,
  )
}

/** Search a `vec0` table for the nearest vectors.
 * Executes synchronously and returns matches ordered by increasing distance.
 * @param db Open NitroSQLite connection with sqlite-vec enabled.
 * @param table Trusted SQL table identifier, interpolated into the statement.

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…