-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: improve doc removal * refactor: change return type
- Loading branch information
Showing
10 changed files
with
98 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { sanitizeFilename } from '@/common/constants/files'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { OpenAIEmbeddings } from 'langchain/embeddings/openai'; | ||
import { Chroma } from 'langchain/vectorstores/chroma'; | ||
|
||
@Injectable() | ||
export class VectorDbService { | ||
constructor(private readonly configService: ConfigService) {} | ||
|
||
getVectorDbClientForNewCollection(roomId: string, filename: string): Chroma { | ||
return new Chroma(new OpenAIEmbeddings(), { | ||
url: this.configService.get('CHROMADB_CONNECTION_URL'), | ||
collectionName: this.getCollectionName(roomId, filename), | ||
}); | ||
} | ||
|
||
async getVectorDbClientForExistingCollection( | ||
roomId: string, | ||
filename: string | ||
): Promise<Chroma> { | ||
return Chroma.fromExistingCollection(new OpenAIEmbeddings(), { | ||
url: this.configService.get('CHROMADB_CONNECTION_URL'), | ||
collectionName: this.getCollectionName(roomId, filename), | ||
}); | ||
} | ||
|
||
private getCollectionName(roomId: string, filename: string) { | ||
return `${roomId}_${sanitizeFilename(filename)}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters