Enha (RAG): raw text as primary key in vector db

This commit is contained in:
Grail Finder
2025-01-07 11:11:44 +03:00
parent b822b3a161
commit 7bbedd93cf
9 changed files with 21 additions and 23 deletions

View File

@@ -88,7 +88,9 @@ func (r *RAG) writeVectors(vectorCh <-chan []models.VectorRow, doneCh <-chan boo
case batch := <-vectorCh:
for _, vector := range batch {
if err := r.store.WriteVector(&vector); err != nil {
return err
r.logger.Error("failed to write vector", "error", err, "slug", vector.Slug)
continue // a duplicate is not critical
// return err
}
}
r.logger.Info("wrote batch to db", "size", len(batch))
@@ -226,14 +228,14 @@ func (r *RAG) LineToVector(line string) ([]float32, error) {
return emb[0], nil
}
func (r *RAG) saveLine(topic, line string, emb *models.EmbeddingResp) error {
row := &models.VectorRow{
Embeddings: emb.Embedding,
Slug: topic,
RawText: line,
}
return r.store.WriteVector(row)
}
// func (r *RAG) saveLine(topic, line string, emb *models.EmbeddingResp) error {
// row := &models.VectorRow{
// Embeddings: emb.Embedding,
// Slug: topic,
// RawText: line,
// }
// return r.store.WriteVector(row)
// }
func (r *RAG) SearchEmb(emb *models.EmbeddingResp) ([]models.VectorRow, error) {
return r.store.SearchClosest(emb.Embedding)