-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
langchain[patch]: Issue #2756 Add Qdrant custom payload on documents to query them by filter #3431
Merged
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
afc6932
Add optional custom payload param and 1 test
Dominik-luszcz 2ed6984
Merge branch 'langchain-ai:main' into development
Dominik-luszcz f28b15b
Add Custom Payload in Documents
Dominik-luszcz 6d83083
Resolve comments in PR
Dominik-luszcz 5a473c2
Merge branch 'main' into development
Dominik-luszcz a378f35
Add document changes to langchain-core
Dominik-luszcz 656f57a
Test because all yarn test cases are passing
Dominik-luszcz 78ef653
Update tests and fix yarn lint
Dominik-luszcz e996840
Remove payload from Document and add object[]
Dominik-luszcz d7f2e53
Remove object[] and replace with objects +comments
Dominik-luszcz 3137c39
Merge
jacoblee93 df87af2
Update add document types
jacoblee93 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
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 | ||||
---|---|---|---|---|---|---|
|
@@ -84,13 +84,18 @@ export class QdrantVectorStore extends VectorStore { | |||||
* from the documents using the `Embeddings` instance and then adds the | ||||||
* vectors to the database. | ||||||
* @param documents Array of `Document` instances to be added to the Qdrant database. | ||||||
* @param customPayload Optional 'object' in JSON format used to query database on more criteria | ||||||
* @returns Promise that resolves when the documents have been added to the database. | ||||||
*/ | ||||||
async addDocuments(documents: Document[]): Promise<void> { | ||||||
async addDocuments( | ||||||
documents: Document[], | ||||||
customPayload?: object | ||||||
): Promise<void> { | ||||||
const texts = documents.map(({ pageContent }) => pageContent); | ||||||
await this.addVectors( | ||||||
await this.embeddings.embedDocuments(texts), | ||||||
documents | ||||||
documents, | ||||||
customPayload | ||||||
); | ||||||
} | ||||||
|
||||||
|
@@ -100,9 +105,14 @@ export class QdrantVectorStore extends VectorStore { | |||||
* database. | ||||||
* @param vectors Array of vectors to be added to the Qdrant database. | ||||||
* @param documents Array of `Document` instances associated with the vectors. | ||||||
* @param customPayload Optional 'object' in JSON format used to query database on more criteria | ||||||
* @returns Promise that resolves when the vectors have been added to the database. | ||||||
*/ | ||||||
async addVectors(vectors: number[][], documents: Document[]): Promise<void> { | ||||||
async addVectors( | ||||||
vectors: number[][], | ||||||
documents: Document[], | ||||||
customPayload?: object | ||||||
): Promise<void> { | ||||||
if (vectors.length === 0) { | ||||||
return; | ||||||
} | ||||||
|
@@ -115,6 +125,8 @@ export class QdrantVectorStore extends VectorStore { | |||||
payload: { | ||||||
content: documents[idx].pageContent, | ||||||
metadata: documents[idx].metadata, | ||||||
...(documents[idx].customPayload ? documents[idx].customPayload != customPayload ? | ||||||
documents[idx].customPayload : customPayload : customPayload), | ||||||
}, | ||||||
})); | ||||||
|
||||||
|
@@ -204,20 +216,23 @@ export class QdrantVectorStore extends VectorStore { | |||||
* @param metadatas Array or single object of metadata to be associated with the texts. | ||||||
* @param embeddings `Embeddings` instance used to generate vectors from the texts. | ||||||
* @param dbConfig `QdrantLibArgs` instance specifying the configuration for the Qdrant database. | ||||||
* @param customPayload Optional 'object' in JSON format used to query database on more criteria | ||||||
* @returns Promise that resolves with a new `QdrantVectorStore` instance. | ||||||
*/ | ||||||
static async fromTexts( | ||||||
texts: string[], | ||||||
metadatas: object[] | object, | ||||||
embeddings: Embeddings, | ||||||
dbConfig: QdrantLibArgs | ||||||
dbConfig: QdrantLibArgs, | ||||||
customPayload? : object | ||||||
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.
Suggested change
nit |
||||||
): Promise<QdrantVectorStore> { | ||||||
const docs = []; | ||||||
for (let i = 0; i < texts.length; i += 1) { | ||||||
const metadata = Array.isArray(metadatas) ? metadatas[i] : metadatas; | ||||||
const newDoc = new Document({ | ||||||
pageContent: texts[i], | ||||||
metadata, | ||||||
customPayload: customPayload, | ||||||
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.
Suggested change
nit |
||||||
}); | ||||||
docs.push(newDoc); | ||||||
} | ||||||
|
@@ -230,15 +245,17 @@ export class QdrantVectorStore extends VectorStore { | |||||
* @param docs Array of `Document` instances to be added to the Qdrant database. | ||||||
* @param embeddings `Embeddings` instance used to generate vectors from the documents. | ||||||
* @param dbConfig `QdrantLibArgs` instance specifying the configuration for the Qdrant database. | ||||||
* @param customPayload Optional 'object' in JSON format used to query database on more criteria | ||||||
* @returns Promise that resolves with a new `QdrantVectorStore` instance. | ||||||
*/ | ||||||
static async fromDocuments( | ||||||
docs: Document[], | ||||||
embeddings: Embeddings, | ||||||
dbConfig: QdrantLibArgs | ||||||
dbConfig: QdrantLibArgs, | ||||||
customPayload?: object | ||||||
): Promise<QdrantVectorStore> { | ||||||
const instance = new this(embeddings, dbConfig); | ||||||
await instance.addDocuments(docs); | ||||||
await instance.addDocuments(docs, customPayload); | ||||||
return instance; | ||||||
} | ||||||
|
||||||
|
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.
Could you just do something like this?
Not sure if this is valid though