feat: Add support for metadata filtering and namespaces for the Upstash Vector component (#3254)
* feat: add metadata filtering and namespace support for the upstash vector component * docs: add upstash vector to the vectorstores doc * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
ac4442d221
commit
ce17bd4e71
2 changed files with 53 additions and 3 deletions
|
|
@ -472,6 +472,27 @@ Ensure the Supabase service key, URL, and table name are properly configured.
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
|
### Upstash Vector
|
||||||
|
|
||||||
|
|
||||||
|
`UpstashVector` searches a Upstash Vector Store for documents similar to the input. It has it's own embedding
|
||||||
|
model which can be used to search documents without needing an external embedding model.
|
||||||
|
|
||||||
|
|
||||||
|
**Parameters:**
|
||||||
|
|
||||||
|
- **Index URL:** The URL of the Upstash index.
|
||||||
|
- **Index Token:** The token for the Upstash index.
|
||||||
|
- **Text Key:** The key in the record to use as text.
|
||||||
|
- **Namespace:** The namespace name. A new namespace is created if not found. Leave empty for default namespace.
|
||||||
|
- **Search Query:** The search query.
|
||||||
|
- **Metadata Filter:** The metadata filter. Filters documents by metadata. Look at the [docs](https://upstash.com/docs/vector/features/filtering) for more information.
|
||||||
|
- **Embedding:** The embedding model used. To use Upstash's embeddings, don't provide an embedding.
|
||||||
|
- **Number of Results:** The number of results to return.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
### Vectara {#b4e05230b62a47c792a89c5511af97ac}
|
### Vectara {#b4e05230b62a47c792a89c5511af97ac}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,14 @@ from langchain_community.vectorstores import UpstashVectorStore
|
||||||
|
|
||||||
from langflow.base.vectorstores.model import LCVectorStoreComponent
|
from langflow.base.vectorstores.model import LCVectorStoreComponent
|
||||||
from langflow.helpers.data import docs_to_data
|
from langflow.helpers.data import docs_to_data
|
||||||
from langflow.io import HandleInput, IntInput, StrInput, SecretStrInput, DataInput, MultilineInput
|
from langflow.io import (
|
||||||
|
HandleInput,
|
||||||
|
IntInput,
|
||||||
|
StrInput,
|
||||||
|
SecretStrInput,
|
||||||
|
DataInput,
|
||||||
|
MultilineInput,
|
||||||
|
)
|
||||||
from langflow.schema import Data
|
from langflow.schema import Data
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -16,9 +23,17 @@ class UpstashVectorStoreComponent(LCVectorStoreComponent):
|
||||||
icon = "Upstash"
|
icon = "Upstash"
|
||||||
|
|
||||||
inputs = [
|
inputs = [
|
||||||
StrInput(name="index_url", display_name="Index URL", info="The URL of the Upstash index.", required=True),
|
StrInput(
|
||||||
|
name="index_url",
|
||||||
|
display_name="Index URL",
|
||||||
|
info="The URL of the Upstash index.",
|
||||||
|
required=True,
|
||||||
|
),
|
||||||
SecretStrInput(
|
SecretStrInput(
|
||||||
name="index_token", display_name="Index Token", info="The token for the Upstash index.", required=True
|
name="index_token",
|
||||||
|
display_name="Index Token",
|
||||||
|
info="The token for the Upstash index.",
|
||||||
|
required=True,
|
||||||
),
|
),
|
||||||
StrInput(
|
StrInput(
|
||||||
name="text_key",
|
name="text_key",
|
||||||
|
|
@ -27,7 +42,17 @@ class UpstashVectorStoreComponent(LCVectorStoreComponent):
|
||||||
value="text",
|
value="text",
|
||||||
advanced=True,
|
advanced=True,
|
||||||
),
|
),
|
||||||
|
StrInput(
|
||||||
|
name="namespace",
|
||||||
|
display_name="Namespace",
|
||||||
|
info="Leave empty for default namespace.",
|
||||||
|
),
|
||||||
MultilineInput(name="search_query", display_name="Search Query"),
|
MultilineInput(name="search_query", display_name="Search Query"),
|
||||||
|
MultilineInput(
|
||||||
|
name="metadata_filter",
|
||||||
|
display_name="Metadata Filter",
|
||||||
|
info="Filters documents by metadata. Look at the documentation for more information.",
|
||||||
|
),
|
||||||
DataInput(
|
DataInput(
|
||||||
name="ingest_data",
|
name="ingest_data",
|
||||||
display_name="Ingest Data",
|
display_name="Ingest Data",
|
||||||
|
|
@ -68,6 +93,7 @@ class UpstashVectorStoreComponent(LCVectorStoreComponent):
|
||||||
text_key=self.text_key,
|
text_key=self.text_key,
|
||||||
index_url=self.index_url,
|
index_url=self.index_url,
|
||||||
index_token=self.index_token,
|
index_token=self.index_token,
|
||||||
|
namespace=self.namespace,
|
||||||
)
|
)
|
||||||
upstash_vs.add_documents(documents)
|
upstash_vs.add_documents(documents)
|
||||||
else:
|
else:
|
||||||
|
|
@ -77,6 +103,7 @@ class UpstashVectorStoreComponent(LCVectorStoreComponent):
|
||||||
text_key=self.text_key,
|
text_key=self.text_key,
|
||||||
index_url=self.index_url,
|
index_url=self.index_url,
|
||||||
index_token=self.index_token,
|
index_token=self.index_token,
|
||||||
|
namespace=self.namespace,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
upstash_vs = UpstashVectorStore(
|
upstash_vs = UpstashVectorStore(
|
||||||
|
|
@ -84,6 +111,7 @@ class UpstashVectorStoreComponent(LCVectorStoreComponent):
|
||||||
text_key=self.text_key,
|
text_key=self.text_key,
|
||||||
index_url=self.index_url,
|
index_url=self.index_url,
|
||||||
index_token=self.index_token,
|
index_token=self.index_token,
|
||||||
|
namespace=self.namespace,
|
||||||
)
|
)
|
||||||
|
|
||||||
return upstash_vs
|
return upstash_vs
|
||||||
|
|
@ -95,6 +123,7 @@ class UpstashVectorStoreComponent(LCVectorStoreComponent):
|
||||||
docs = vector_store.similarity_search(
|
docs = vector_store.similarity_search(
|
||||||
query=self.search_query,
|
query=self.search_query,
|
||||||
k=self.number_of_results,
|
k=self.number_of_results,
|
||||||
|
filter=self.metadata_filter,
|
||||||
)
|
)
|
||||||
|
|
||||||
data = docs_to_data(docs)
|
data = docs_to_data(docs)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue