Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions internal/rag/openai_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ func (o *OpenAIProvider) Initialize(ctx context.Context) error {

// IngestFile uploads a file to the OpenAI vector store
func (o *OpenAIProvider) IngestFile(ctx context.Context, filePath string, metadata map[string]string) (string, error) {
// Check if vector store ID is empty
if o.vectorStoreID == "" {
// Use dynamic vector store
fmt.Printf("[RAG] OpenAI: Using dynamic vector store\n")
vectorStoreID, err := o.searchVectorStore(ctx, o.config.VectorStoreNameRegex)
if err != nil {
return "", fmt.Errorf("failed to search vector store: %w", err)
}
o.vectorStoreID = vectorStoreID
}
// Open the file for upload
file, err := os.Open(filePath)
if err != nil {
Expand Down Expand Up @@ -199,6 +209,15 @@ func (o *OpenAIProvider) IngestFiles(ctx context.Context, filePaths []string, me

// DeleteFile removes a file from the vector store
func (o *OpenAIProvider) DeleteFile(ctx context.Context, fileID string) error {
if o.vectorStoreID == "" {
// Use dynamic vector store
fmt.Printf("[RAG] OpenAI: Using dynamic vector store\n")
vectorStoreID, err := o.searchVectorStore(ctx, o.config.VectorStoreNameRegex)
if err != nil {
return fmt.Errorf("failed to search vector store: %w", err)
}
o.vectorStoreID = vectorStoreID
}
// Remove from vector store first
_, err := o.client.VectorStores.Files.Delete(ctx, o.vectorStoreID, fileID)
if err != nil {
Expand All @@ -217,6 +236,15 @@ func (o *OpenAIProvider) DeleteFile(ctx context.Context, fileID string) error {

// ListFiles lists all files in the vector store
func (o *OpenAIProvider) ListFiles(ctx context.Context, limit int) ([]FileInfo, error) {
if o.vectorStoreID == "" {
// Use dynamic vector store
fmt.Printf("[RAG] OpenAI: Using dynamic vector store\n")
vectorStoreID, err := o.searchVectorStore(ctx, o.config.VectorStoreNameRegex)
if err != nil {
return nil, fmt.Errorf("failed to search vector store: %w", err)
}
o.vectorStoreID = vectorStoreID
}
// List vector store files
vsFiles, err := o.client.VectorStores.Files.List(ctx, o.vectorStoreID, openai.VectorStoreFileListParams{
Limit: openai.Int(int64(limit)),
Expand Down Expand Up @@ -340,6 +368,15 @@ func (o *OpenAIProvider) Search(ctx context.Context, query string, options Searc

// GetStats returns statistics about the vector store
func (o *OpenAIProvider) GetStats(ctx context.Context) (*VectorStoreStats, error) {
if o.vectorStoreID == "" {
// Use dynamic vector store
fmt.Printf("[RAG] OpenAI: Using dynamic vector store\n")
vectorStoreID, err := o.searchVectorStore(ctx, o.config.VectorStoreNameRegex)
if err != nil {
return nil, fmt.Errorf("failed to search vector store: %w", err)
}
o.vectorStoreID = vectorStoreID
}
// Get vector store details
vs, err := o.client.VectorStores.Get(ctx, o.vectorStoreID)
if err != nil {
Expand Down
Loading