feat: Integrate LLM-based reranking in KnowledgeSearchTool
- Added optional chat model to KnowledgeSearchTool for enhanced reranking using LLM prompt scoring. - Updated rerankResults method to prioritize LLM-based reranking over traditional rerank model. - Implemented new functions for LLM scoring and parsing scores from responses, improving search result relevance. - Enhanced migration script to handle database versioning and dirty state checks more robustly.
This commit is contained in:
@@ -23,11 +23,59 @@ func RunMigrations(dsn string) error {
|
||||
}
|
||||
defer m.Close()
|
||||
|
||||
// Get current version before migration
|
||||
oldVersion, _, _ := m.Version()
|
||||
// Check current version and dirty state before migration
|
||||
oldVersion, oldDirty, versionErr := m.Version()
|
||||
if versionErr != nil && versionErr != migrate.ErrNilVersion {
|
||||
// If we can't get version and it's not because database is empty, return error
|
||||
return fmt.Errorf("failed to get migration version: %w", versionErr)
|
||||
}
|
||||
|
||||
// If database is in dirty state, return detailed error with fix instructions
|
||||
if oldDirty {
|
||||
// Calculate the version to force to (usually the previous version)
|
||||
forceVersion := int(oldVersion) - 1
|
||||
if oldVersion == 0 || forceVersion < 0 {
|
||||
forceVersion = 0
|
||||
}
|
||||
return fmt.Errorf(
|
||||
"database is in dirty state at version %d. This usually means a migration failed partway through. "+
|
||||
"To fix this:\n"+
|
||||
"1. Check if the migration partially applied changes and manually fix if needed\n"+
|
||||
"2. Use the force command to set the version to the last successful migration (usually %d):\n"+
|
||||
" ./scripts/migrate.sh force %d\n"+
|
||||
" Or if using make: make migrate-force version=%d\n"+
|
||||
"3. After fixing, restart the application to retry the migration",
|
||||
oldVersion,
|
||||
forceVersion,
|
||||
forceVersion,
|
||||
forceVersion,
|
||||
)
|
||||
}
|
||||
|
||||
// Run all pending migrations
|
||||
if err := m.Up(); err != nil && err != migrate.ErrNoChange {
|
||||
// Check if error is due to dirty state (in case it became dirty during migration)
|
||||
currentVersion, currentDirty, versionCheckErr := m.Version()
|
||||
if versionCheckErr == nil && currentDirty {
|
||||
// Calculate the version to force to (usually the previous version)
|
||||
forceVersion := currentVersion - 1
|
||||
if currentVersion == 0 {
|
||||
forceVersion = 0
|
||||
}
|
||||
return fmt.Errorf(
|
||||
"migration failed and database is now in dirty state at version %d. "+
|
||||
"To fix this:\n"+
|
||||
"1. Check if the migration partially applied changes and manually fix if needed\n"+
|
||||
"2. Use the force command to set the version to the last successful migration (usually %d):\n"+
|
||||
" ./scripts/migrate.sh force %d\n"+
|
||||
" Or if using make: make migrate-force version=%d\n"+
|
||||
"3. After fixing, restart the application to retry the migration",
|
||||
currentVersion,
|
||||
forceVersion,
|
||||
forceVersion,
|
||||
forceVersion,
|
||||
)
|
||||
}
|
||||
return fmt.Errorf("failed to run migrations: %w", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user