Skip to content

Commit 4c113d5

Browse files
authored
Add Upstash Vector Store support (#2004)
* docs(migration): add UPSTASH_VECTOR_REST_URL and UPSTASH_VECTOR_REST_TOKEN to the list of default environment variables pyproject.toml: add upstash-vector package as a dependency with version 0.4.0 src/backend/base/langflow/components/vectorsearch/UpstashSearch.py: create UpstashSearchComponent for implementing a Vector Store using Upstash src/backend/base/langflow/components/vectorstores/Upstash.py: create UpstashVectorStoreComponent for implementing a Vector Store using Upstash src/backend/base/langflow/services/settings/constants.py: add UPSTASH_VECTOR_REST_URL and UPSTASH_VECTOR_REST_TOKEN to the list of variables to get from the environment * ✨ (UpstashSearch.py): Add support for 'number_of_results' and 'text_key' parameters in UpstashSearchComponent to enhance search functionality ♻️ (Upstash.py): Refactor UpstashVectorStoreComponent to include 'text_key' parameter for consistency and improved functionality * ♻️ (Upstash.py): refactor UpstashVectorStoreComponent to improve code readability and maintainability by restructuring the instantiation of UpstashVectorStore instances based on conditions and adding support for adding documents directly to the instance. * feat: Update langchain-core, langchainhub, langsmith, and requests dependencies to latest versions
1 parent 39f86a4 commit 4c113d5

File tree

7 files changed

+239
-52
lines changed

7 files changed

+239
-52
lines changed

docs/docs/migration/global-variables.mdx

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ The default list at the moment is:
105105
- PINECONE_API_KEY
106106
- SEARCHAPI_API_KEY
107107
- SERPAPI_API_KEY
108+
- UPSTASH_VECTOR_REST_URL
109+
- UPSTASH_VECTOR_REST_TOKEN
108110
- VECTARA_CUSTOMER_ID
109111
- VECTARA_CORPUS_ID
110112
- VECTARA_API_KEY

poetry.lock

+54-40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ couchbase = "^4.2.1"
8585
youtube-transcript-api = "^0.6.2"
8686
markdown = "^3.6"
8787
langchain-chroma = "^0.1.1"
88+
upstash-vector = "^0.4.0"
8889

8990

9091
[tool.poetry.group.dev.dependencies]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
from typing import List, Optional
2+
3+
from langchain_core.embeddings import Embeddings
4+
5+
from langflow.components.vectorstores.base.model import LCVectorStoreComponent
6+
from langflow.components.vectorstores.Upstash import UpstashVectorStoreComponent
7+
from langflow.field_typing import Text
8+
from langflow.schema import Record
9+
10+
11+
class UpstashSearchComponent(UpstashVectorStoreComponent, LCVectorStoreComponent):
12+
"""
13+
A custom component for implementing a Vector Store using Upstash.
14+
"""
15+
16+
display_name: str = "Upstash Search"
17+
description: str = "Search an Upstash Vector Store for similar documents."
18+
19+
def build_config(self):
20+
"""
21+
Builds the configuration for the component.
22+
23+
Returns:
24+
- dict: A dictionary containing the configuration options for the component.
25+
"""
26+
return {
27+
"search_type": {
28+
"display_name": "Search Type",
29+
"options": ["Similarity", "MMR"],
30+
},
31+
"input_value": {"display_name": "Input"},
32+
"inputs": {"display_name": "Input", "input_types": ["Document", "Record"]},
33+
"embedding": {
34+
"display_name": "Embedding",
35+
"input_types": ["Embeddings"],
36+
"info": "To use Upstash's embeddings, don't provide an embedding.",
37+
},
38+
"index_url": {
39+
"display_name": "Index URL",
40+
"info": "The URL of the Upstash index.",
41+
},
42+
"index_token": {
43+
"display_name": "Index Token",
44+
"info": "The token for the Upstash index.",
45+
},
46+
"number_of_results": {
47+
"display_name": "Number of Results",
48+
"info": "Number of results to return.",
49+
"advanced": True,
50+
},
51+
"text_key": {
52+
"display_name": "Text Key",
53+
"info": "The key in the record to use as text.",
54+
"advanced": True,
55+
},
56+
}
57+
58+
def build( # type: ignore[override]
59+
self,
60+
input_value: Text,
61+
search_type: str,
62+
text_key: str = "text",
63+
index_url: Optional[str] = None,
64+
index_token: Optional[str] = None,
65+
embedding: Optional[Embeddings] = None,
66+
number_of_results: int = 4,
67+
) -> List[Record]:
68+
vector_store = super().build(
69+
embedding=embedding,
70+
text_key=text_key,
71+
index_url=index_url,
72+
index_token=index_token,
73+
)
74+
if not vector_store:
75+
raise ValueError("Failed to load the Upstash Vector Store.")
76+
77+
return self.search_with_vector_store(
78+
input_value=input_value, search_type=search_type, vector_store=vector_store, k=number_of_results
79+
)

0 commit comments

Comments
 (0)