46 lines
1.9 KiB
Go
46 lines
1.9 KiB
Go
package domain
|
|
|
|
import "context"
|
|
|
|
// EmbeddingDim is the vector width migrations/0001_init.sql declares
|
|
// for documents.embedding (vector(768), matching nomic-embed-text).
|
|
const EmbeddingDim = 768
|
|
|
|
// CodeChunk is a single embedded chunk of a source file, as returned by
|
|
// a similarity search — identical in shape to the monolith's
|
|
// models.CodeChunk.
|
|
type CodeChunk struct {
|
|
ID int64
|
|
FilePath string
|
|
ChunkIndex int
|
|
Content string
|
|
Distance float64 // cosine distance; lower = more relevant
|
|
}
|
|
|
|
// Embedder is the subset of *vllmkit.Client the application layer
|
|
// needs — defined here (rather than depending on the concrete client
|
|
// type) purely to keep the dependency explicit and mockable in tests,
|
|
// exactly like the monolith's rag.Embedder.
|
|
type Embedder interface {
|
|
Embed(ctx context.Context, text string) ([]float32, error)
|
|
}
|
|
|
|
// DocumentRepository persists chunked, embedded documents — the
|
|
// pgvector-backed transplant of internal/rag/store.go +
|
|
// internal/rag/index.go's pruneMissing.
|
|
type DocumentRepository interface {
|
|
// ExistingContentHash returns the content_hash stored for
|
|
// (filePath, chunkIndex), or "" if no such row exists — used to
|
|
// skip re-embedding an unchanged chunk (see UpsertChunk's doc
|
|
// comment in the monolith).
|
|
ExistingContentHash(ctx context.Context, filePath string, chunkIndex int) (string, error)
|
|
Upsert(ctx context.Context, filePath string, chunkIndex int, content, contentHash string, embedding []float32) error
|
|
// DeleteChunksFrom removes any chunk_index >= fromIndex for
|
|
// filePath — stale trailing chunks left over from a previous,
|
|
// longer version of the file.
|
|
DeleteChunksFrom(ctx context.Context, filePath string, fromIndex int) error
|
|
Search(ctx context.Context, embedding []float32, topK int) ([]CodeChunk, error)
|
|
PruneMissing(ctx context.Context, keepFilePaths []string) (int, error)
|
|
ListIndexedFiles(ctx context.Context, limit int) ([]string, error)
|
|
}
|