Documentation
¶
Index ¶
- Constants
- type CodeChunkService
- func (ccs *CodeChunkService) Close() error
- func (ccs *CodeChunkService) CreateCollection(ctx context.Context, collectionName string) error
- func (ccs *CodeChunkService) DeleteCollection(ctx context.Context, collectionName string) error
- func (ccs *CodeChunkService) GetEmbeddingModel() EmbeddingModel
- func (ccs *CodeChunkService) GetVectorDB() VectorDatabase
- func (ccs *CodeChunkService) IndexMethodSignatures(ctx context.Context, collectionName string, signatures []MethodSignatureData) error
- func (ccs *CodeChunkService) ProcessDirectory(ctx context.Context, dirPath, collectionName string, repoConfig interface{}) (int, error)
- func (ccs *CodeChunkService) ProcessFile(ctx context.Context, filePath, language, collectionName string) ([]*model.CodeChunk, error)
- func (ccs *CodeChunkService) ProcessFileWithContentAndFileID(ctx context.Context, filePath, language, collectionName string, ...) ([]*model.CodeChunk, error)
- func (ccs *CodeChunkService) ReadCodeFromFile(filePath string, startLine, endLine int) (string, error)
- func (ccs *CodeChunkService) SearchMethodSignatures(ctx context.Context, collectionName, query string, limit int) ([]*model.CodeChunk, []float32, error)
- func (ccs *CodeChunkService) SearchSimilarCode(ctx context.Context, collectionName, queryText string, limit int, ...) ([]*model.CodeChunk, []float32, error)
- func (ccs *CodeChunkService) SearchSimilarCodeBySnippet(ctx context.Context, collectionName, codeSnippet, language string, limit int, ...) ([]*model.CodeChunk, []*model.CodeChunk, []float32, []int, error)
- type DistanceMetric
- type EmbeddingModel
- type MethodSignatureData
- type OllamaEmbedding
- type OllamaEmbeddingConfig
- type QdrantDatabase
- func (q *QdrantDatabase) Close() error
- func (q *QdrantDatabase) CollectionExists(ctx context.Context, collectionName string) (bool, error)
- func (q *QdrantDatabase) CreateCollection(ctx context.Context, collectionName string, vectorDim int, ...) error
- func (q *QdrantDatabase) DeleteChunk(ctx context.Context, collectionName string, chunkID string) error
- func (q *QdrantDatabase) DeleteCollection(ctx context.Context, collectionName string) error
- func (q *QdrantDatabase) GetChunkByID(ctx context.Context, collectionName string, chunkID string) (*model.CodeChunk, error)
- func (q *QdrantDatabase) GetChunksByFilePath(ctx context.Context, collectionName string, filePath string) ([]*model.CodeChunk, error)
- func (q *QdrantDatabase) Health(ctx context.Context) error
- func (q *QdrantDatabase) SearchSimilar(ctx context.Context, collectionName string, queryVector []float32, limit int, ...) ([]*model.CodeChunk, []float32, error)
- func (q *QdrantDatabase) UpsertChunks(ctx context.Context, collectionName string, chunks []*model.CodeChunk) error
- type VectorDatabase
Constants ¶
const ( // NomicEmbedText is a high-quality 768-dimensional embedding model NomicEmbedText = "nomic-embed-text" // AllMiniLM is a lightweight 384-dimensional embedding model AllMiniLM = "all-minilm" // MxbaiEmbedLarge is a large 1024-dimensional embedding model MxbaiEmbedLarge = "mxbai-embed-large" )
Common Ollama embedding models
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CodeChunkService ¶
type CodeChunkService struct {
// contains filtered or unexported fields
}
CodeChunkService orchestrates code chunking, embedding, and vector storage
func NewCodeChunkService ¶
func NewCodeChunkService(vectorDB VectorDatabase, embedding EmbeddingModel, minConditionalLines, minLoopLines int, gcThreshold int64, numFileThreads int, logger *zap.Logger) *CodeChunkService
NewCodeChunkService creates a new code chunk service
func (*CodeChunkService) Close ¶
func (ccs *CodeChunkService) Close() error
Close closes all resources
func (*CodeChunkService) CreateCollection ¶
func (ccs *CodeChunkService) CreateCollection(ctx context.Context, collectionName string) error
CreateCollection creates a new collection in the vector database
func (*CodeChunkService) DeleteCollection ¶
func (ccs *CodeChunkService) DeleteCollection(ctx context.Context, collectionName string) error
DeleteCollection deletes a collection from the vector database
func (*CodeChunkService) GetEmbeddingModel ¶
func (ccs *CodeChunkService) GetEmbeddingModel() EmbeddingModel
GetEmbeddingModel returns the embedding model instance
func (*CodeChunkService) GetVectorDB ¶
func (ccs *CodeChunkService) GetVectorDB() VectorDatabase
GetVectorDB returns the vector database instance
func (*CodeChunkService) IndexMethodSignatures ¶
func (ccs *CodeChunkService) IndexMethodSignatures(ctx context.Context, collectionName string, signatures []MethodSignatureData) error
IndexMethodSignatures indexes method signatures for semantic search The normalized signature text is embedded and stored separately from code content
func (*CodeChunkService) ProcessDirectory ¶
func (ccs *CodeChunkService) ProcessDirectory(ctx context.Context, dirPath, collectionName string, repoConfig interface{}) (int, error)
ProcessDirectory processes all supported files in a directory recursively Gracefully skips files that fail to read or process
func (*CodeChunkService) ProcessFile ¶
func (ccs *CodeChunkService) ProcessFile(ctx context.Context, filePath, language, collectionName string) ([]*model.CodeChunk, error)
ProcessFile processes a single source file and stores chunks in vector DB Returns (chunks, error) - if error is non-nil, processing failed but can be retried
func (*CodeChunkService) ProcessFileWithContentAndFileID ¶
func (ccs *CodeChunkService) ProcessFileWithContentAndFileID(ctx context.Context, filePath, language, collectionName string, sourceCode []byte, fileID int32) ([]*model.CodeChunk, error)
ProcessFileWithContentAndFileID processes a single source file with provided content and FileID This version is used by the IndexBuilder which provides centralized FileID from MySQL Returns (chunks, error) - if error is non-nil, processing failed but can be retried
func (*CodeChunkService) ReadCodeFromFile ¶
func (ccs *CodeChunkService) ReadCodeFromFile(filePath string, startLine, endLine int) (string, error)
ReadCodeFromFile reads specific lines from a file
func (*CodeChunkService) SearchMethodSignatures ¶
func (ccs *CodeChunkService) SearchMethodSignatures(ctx context.Context, collectionName, query string, limit int) ([]*model.CodeChunk, []float32, error)
SearchMethodSignatures searches for methods by natural language query on their signatures
func (*CodeChunkService) SearchSimilarCode ¶
func (ccs *CodeChunkService) SearchSimilarCode(ctx context.Context, collectionName, queryText string, limit int, filter map[string]interface{}) ([]*model.CodeChunk, []float32, error)
SearchSimilarCode searches for code chunks similar to the given query text
func (*CodeChunkService) SearchSimilarCodeBySnippet ¶
func (ccs *CodeChunkService) SearchSimilarCodeBySnippet(ctx context.Context, collectionName, codeSnippet, language string, limit int, filter map[string]interface{}) ([]*model.CodeChunk, []*model.CodeChunk, []float32, []int, error)
SearchSimilarCodeBySnippet chunks a code snippet and searches for similar code in the database
type DistanceMetric ¶
type DistanceMetric string
DistanceMetric represents the distance metric used for vector similarity
const ( // DistanceMetricCosine uses cosine similarity (best for normalized embeddings) DistanceMetricCosine DistanceMetric = "cosine" // DistanceMetricDot uses dot product similarity DistanceMetricDot DistanceMetric = "dot" // DistanceMetricEuclidean uses Euclidean distance DistanceMetricEuclidean DistanceMetric = "euclidean" )
type EmbeddingModel ¶
type EmbeddingModel interface {
// GenerateEmbedding generates a vector embedding for the given text
GenerateEmbedding(ctx context.Context, text string) ([]float32, error)
// GenerateEmbeddings generates vector embeddings for multiple texts (batch operation)
GenerateEmbeddings(ctx context.Context, texts []string) ([][]float32, error)
// GetDimension returns the dimension of the embedding vectors
GetDimension() int
// GetModelName returns the name of the embedding model being used
GetModelName() string
}
EmbeddingModel represents a generic embedding model interface This abstraction allows swapping between Ollama, OpenAI, Cohere, etc.
type MethodSignatureData ¶
type MethodSignatureData struct {
MethodName string
ClassName string
ReturnType string
ParameterTypes []string
ParameterNames []string
FilePath string
StartLine int
EndLine int
FileID int32
}
MethodSignatureData holds information for indexing a method signature
type OllamaEmbedding ¶
type OllamaEmbedding struct {
// contains filtered or unexported fields
}
OllamaEmbedding implements EmbeddingModel interface using Ollama
func NewOllamaEmbedding ¶
func NewOllamaEmbedding(config OllamaEmbeddingConfig, logger *zap.Logger) (*OllamaEmbedding, error)
NewOllamaEmbedding creates a new Ollama embedding model client
func (*OllamaEmbedding) GenerateEmbedding ¶
GenerateEmbedding generates a vector embedding for the given text
func (*OllamaEmbedding) GenerateEmbeddings ¶
func (o *OllamaEmbedding) GenerateEmbeddings(ctx context.Context, texts []string) ([][]float32, error)
GenerateEmbeddings generates vector embeddings for multiple texts (batch operation)
func (*OllamaEmbedding) GetDimension ¶
func (o *OllamaEmbedding) GetDimension() int
GetDimension returns the dimension of the embedding vectors
func (*OllamaEmbedding) GetModelName ¶
func (o *OllamaEmbedding) GetModelName() string
GetModelName returns the name of the embedding model being used
type OllamaEmbeddingConfig ¶
type OllamaEmbeddingConfig struct {
APIURL string // e.g., "http://localhost:11434"
APIKey string // Optional API key for authentication
Model string // e.g., "nomic-embed-text", "all-minilm"
Dimension int // Dimension of the embedding vector
}
OllamaEmbeddingConfig holds configuration for Ollama embedding model
type QdrantDatabase ¶
type QdrantDatabase struct {
// contains filtered or unexported fields
}
QdrantDatabase implements VectorDatabase interface using Qdrant
func NewQdrantDatabase ¶
func NewQdrantDatabase(host string, port int, apiKey string, logger *zap.Logger) (*QdrantDatabase, error)
NewQdrantDatabase creates a new Qdrant database connection
func (*QdrantDatabase) Close ¶
func (q *QdrantDatabase) Close() error
Close closes the database connection
func (*QdrantDatabase) CollectionExists ¶
CollectionExists checks if a collection exists
func (*QdrantDatabase) CreateCollection ¶
func (q *QdrantDatabase) CreateCollection(ctx context.Context, collectionName string, vectorDim int, distance DistanceMetric) error
CreateCollection creates a new collection with the specified dimension and distance metric
func (*QdrantDatabase) DeleteChunk ¶
func (q *QdrantDatabase) DeleteChunk(ctx context.Context, collectionName string, chunkID string) error
DeleteChunk deletes a chunk by its ID
func (*QdrantDatabase) DeleteCollection ¶
func (q *QdrantDatabase) DeleteCollection(ctx context.Context, collectionName string) error
DeleteCollection deletes a collection
func (*QdrantDatabase) GetChunkByID ¶
func (q *QdrantDatabase) GetChunkByID(ctx context.Context, collectionName string, chunkID string) (*model.CodeChunk, error)
GetChunkByID retrieves a specific chunk by its ID
func (*QdrantDatabase) GetChunksByFilePath ¶
func (q *QdrantDatabase) GetChunksByFilePath(ctx context.Context, collectionName string, filePath string) ([]*model.CodeChunk, error)
GetChunksByFilePath retrieves all chunks for a specific file path
func (*QdrantDatabase) Health ¶
func (q *QdrantDatabase) Health(ctx context.Context) error
Health checks the health of the vector database
func (*QdrantDatabase) SearchSimilar ¶
func (q *QdrantDatabase) SearchSimilar(ctx context.Context, collectionName string, queryVector []float32, limit int, filter map[string]interface{}) ([]*model.CodeChunk, []float32, error)
SearchSimilar finds similar code chunks using vector similarity search
func (*QdrantDatabase) UpsertChunks ¶
func (q *QdrantDatabase) UpsertChunks(ctx context.Context, collectionName string, chunks []*model.CodeChunk) error
UpsertChunks inserts or updates code chunks in the vector database
type VectorDatabase ¶
type VectorDatabase interface {
// CreateCollection creates a new collection with the specified dimension and distance metric
CreateCollection(ctx context.Context, collectionName string, vectorDim int, distance DistanceMetric) error
// DeleteCollection deletes a collection
DeleteCollection(ctx context.Context, collectionName string) error
// CollectionExists checks if a collection exists
CollectionExists(ctx context.Context, collectionName string) (bool, error)
// UpsertChunks inserts or updates code chunks in the vector database
UpsertChunks(ctx context.Context, collectionName string, chunks []*model.CodeChunk) error
// SearchSimilar finds similar code chunks using vector similarity search
SearchSimilar(ctx context.Context, collectionName string, queryVector []float32, limit int, filter map[string]interface{}) ([]*model.CodeChunk, []float32, error)
// GetChunkByID retrieves a specific chunk by its ID
GetChunkByID(ctx context.Context, collectionName string, chunkID string) (*model.CodeChunk, error)
// DeleteChunk deletes a chunk by its ID
DeleteChunk(ctx context.Context, collectionName string, chunkID string) error
// GetChunksByFilePath retrieves all chunks for a specific file path
GetChunksByFilePath(ctx context.Context, collectionName string, filePath string) ([]*model.CodeChunk, error)
// Close closes the database connection
Close() error
// Health checks the health of the vector database
Health(ctx context.Context) error
}
VectorDatabase represents a generic vector database interface This abstraction allows swapping between Qdrant, Weaviate, Pinecone, etc.