How to use RedisVectorStoreFilterType? #5010
Replies: 2 comments 1 reply
-
Based on the context provided, the To use
However, the exact implementation details and method signatures are not provided in the context, so you would need to refer to the Regarding the structure and format of the filter strings, they can be either an array of strings or a single string containing space-separated values. When passed as an array of strings, each element in the array represents a filter criterion. The method internally converts this array into a Redis search query format by joining the array elements with the OR operator ( Here are some examples from the test cases in the LangChain JS codebase:
await store.similaritySearch("hello", 1, ["a", "b", "c"]);
expect(client.ft.search).toHaveBeenCalledWith(
"documents",
"@metadata:(a|b|c) => [KNN 1 @content_vector $vector AS vector_score]",
...
);
await store.similaritySearch("hello", 1, "a b c");
expect(client.ft.search).toHaveBeenCalledWith(
"documents",
"@metadata:(a b c) => [KNN 1 @content_vector $vector AS vector_score]",
...
); You can find these examples in the LangChain JS codebase. I hope this helps! If you have any more questions or need further clarification, feel free to ask. Sources
|
Beta Was this translation helpful? Give feedback.
-
Hi, Thanks for the explanation... I was expecting that the metadata field could be a JSON object... But it seems that it cant. Looking at this portion of the RedisVectorStore implementation, it seems that I can only filter on the metadata key, which should map to a string (or many strings), which are used to build the filter condition. let hybridFields = "*";
// if a filter is set, modify the hybrid query
if (filter && filter.length) {
// `filter` is a list of strings, then it's applied using the OR operator in the metadata key
// for example: filter = ['foo', 'bar'] => this will filter all metadata containing either 'foo' OR 'bar'
hybridFields = `@${this.metadataKey}:(${this.prepareFilter(filter)})`;
} It seems a bug to me.. As the export interface DocumentInput<Metadata extends Record<string, any> = Record<string, any>> {
pageContent: string;
metadata?: Metadata;
}
export interface DocumentInterface<Metadata extends Record<string, any> = Record<string, any>> {
pageContent: string;
metadata: Metadata;
}
/**
* Interface for interacting with a document.
*/
export declare class Document<Metadata extends Record<string, any> = Record<string, any>> implements DocumentInput, DocumentInterface {
pageContent: string;
metadata: Metadata;
constructor(fields: DocumentInput<Metadata>);
} Looking at the Redis data, I can see that the |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
Hi,
I am trying to understand how RedisVectorStore search works when we have filters.
Filters are defined as an array of strings, and I am having a hard time to understand how these strings are related to the metadata fields.
Any help would be much appreciated.
Thank you!
System Info
langchain@0.1.31 | MIT | deps: 17 | versions: 262
Beta Was this translation helpful? Give feedback.
All reactions