migrate_sqlite_to_pgvector

View as MarkdownOpen in Claude

Migrate a .swsearch SQLite index to a pgvector collection in PostgreSQL. Chunks are transferred in batches with their embeddings, metadata, and tags preserved.

Parameters

sqlite_path
strRequired

Path to the source .swsearch file.

connection_string
strRequired

PostgreSQL connection string (e.g., "postgresql://user:pass@host/db").

collection_name
strRequired

Name for the target pgvector collection.

overwrite
boolDefaults to false

Drop and recreate the collection if it already exists.

batch_size
intDefaults to 100

Number of chunks to insert per batch.

Returns

dict[str, Any] — Migration statistics containing:

  • source (str) — source file path
  • target (str) — target collection name
  • chunks_migrated (int) — number of successfully migrated chunks
  • errors (int) — number of failed chunks
  • config (dict) — source index configuration

Example

from signalwire.search import SearchIndexMigrator
migrator = SearchIndexMigrator(verbose=True)
stats = migrator.migrate_sqlite_to_pgvector(
sqlite_path="./knowledge.swsearch",
connection_string="postgresql://user:pass@localhost/mydb",
collection_name="knowledge",
overwrite=True,
)
print(f"Migrated {stats['chunks_migrated']} chunks with {stats['errors']} errors")