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

1from signalwire.search import SearchIndexMigrator
2
3migrator = SearchIndexMigrator(verbose=True)
4stats = migrator.migrate_sqlite_to_pgvector(
5 sqlite_path="./knowledge.swsearch",
6 connection_string="postgresql://user:pass@localhost/mydb",
7 collection_name="knowledge",
8 overwrite=True,
9)
10
11print(f"Migrated {stats['chunks_migrated']} chunks with {stats['errors']} errors")