-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: abstracting the creation of a vector store #47
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
35e4b2c
refactor: abstracting the creation of a vector store.
SEBRATHEZEBRA ed8a777
chore: reviewed changes
SEBRATHEZEBRA dbeb902
chore: remove unused imports
SEBRATHEZEBRA 5921a09
Merge branch 'main' into refactor/memory-vector-store-abstraction
SEBRATHEZEBRA 958e518
chore: test fix
SEBRATHEZEBRA 9245307
chore: including new test file in filterFile test
SEBRATHEZEBRA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { MemoryVectorStore } from 'langchain/vectorstores/memory'; | ||
import { CreateMemoryStore } from './createMemoryStore'; | ||
import { OpenAIEmbeddings } from 'langchain/embeddings/openai'; | ||
|
||
describe('CreateMemoryStore function', () => { | ||
const initialFiles = [ | ||
{ | ||
pageContent: '**LOGAF Level 1 - src/test/cases/.cache/faee919bf4f6a5b85a44b1a8eacc0ca24223d6c4033a2b4c52bc79bb8e1bc1bb.ts**\n' + | ||
'\n' + | ||
'The code exposes a secret key which is a serious security issue. Never log sensitive information like API keys, passwords, or secrets. Consider using environment variables to store such sensitive information. For example:\n' + | ||
'\n' + | ||
'```typescript\n' + | ||
'const secretKey = process.env.SECRET_KEY;\n' + | ||
'\n' + | ||
'function exposeSecret() {\n' + | ||
' console.log(`The secret key is: ${secretKey}`);\n' + | ||
'}\n' + | ||
'\n' + | ||
'exposeSecret();\n' + | ||
'```\n' + | ||
'\n' + | ||
'In this case, the secret key is stored in an environment variable named `SECRET_KEY`. Remember to add `SECRET_KEY` to your `.env` file and never commit the `.env` file to the repository.\n' + | ||
'\n' + | ||
'🔑❌🔒\n', | ||
metadata: { | ||
source: '/Users/sebo/Desktop/aleios/code-review-gpt/src/test/cases/snapshots/exposed-secret.md' | ||
} | ||
}, | ||
{ | ||
pageContent: '**LOGAF Level 1 - src/test/cases/.cache/5519e4e1b45143a504ec259a5d911dea930372c19b3f56b51afab53f55339b56.ts**\n' + | ||
'\n' + | ||
'The function `nestedLoops` has too many nested loops which can lead to performance issues and is hard to read and maintain. Consider refactoring the code to reduce the number of nested loops. If the logic of the code allows, you could use recursion or divide the task into smaller functions. Here is an example of how you could refactor this code using recursion:\n' + | ||
'\n' + | ||
'```\n' + | ||
'function recursiveLoop(depth, maxDepth, maxCount) {\n' + | ||
' if (depth === maxDepth) {\n' + | ||
' console.log(...arguments);\n' + | ||
' } else {\n' + | ||
' for (let i = 0; i < maxCount; i++) {\n' + | ||
' recursiveLoop(i, depth + 1, maxDepth, maxCount);\n' + | ||
' }\n' + | ||
' }\n' + | ||
'}\n' + | ||
'\n' + | ||
'recursiveLoop(0, 10, 10);\n' + | ||
'```\n' + | ||
'\n' + | ||
'This code does the same thing as the original code but is much easier to read and maintain.\n' + | ||
'\n' + | ||
'🔄🐌🔧\n', | ||
metadata: { | ||
source: '/Users/sebo/Desktop/aleios/code-review-gpt/src/test/cases/snapshots/too-many-nested-loops.md' | ||
} | ||
}, | ||
]; | ||
it('Checks that the CreateMemoryStore function returns a MemoryVectorStore object', () => { | ||
const result = CreateMemoryStore(initialFiles); | ||
|
||
expect(result).toBeInstanceOf(Promise<MemoryVectorStore>); | ||
}); | ||
|
||
it('Checks if the function provides the required functionality', async () => { | ||
const result = await CreateMemoryStore(initialFiles); | ||
|
||
const expectedResult = await MemoryVectorStore.fromDocuments( | ||
initialFiles, | ||
new OpenAIEmbeddings(), | ||
{} | ||
); | ||
expect(result).toEqual(expectedResult); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also can you check that a simularitySearchWithScore returns a number. Thats the most used method on this class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done :) |
||
}); | ||
}); |
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,13 @@ | ||
import { Document } from 'langchain/dist/document'; | ||
import { OpenAIEmbeddings } from 'langchain/embeddings/openai'; | ||
import { MemoryVectorStore } from 'langchain/vectorstores/memory'; | ||
|
||
export const CreateMemoryStore = async (initialFiles: Document<Record<string, any>>[]): Promise<MemoryVectorStore> => { | ||
const embeddingModel = new OpenAIEmbeddings(); | ||
|
||
return await MemoryVectorStore.fromDocuments( | ||
initialFiles, | ||
embeddingModel, | ||
{} | ||
); | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you make this file in the testFiles and then read it here. Makes the code a lot nicer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done :)