Find answers from the community

Updated 9 months ago

Failing to retrieve documents once the

Failing to retrieve documents once the app is reloads storage context
Plain Text
redis_client = redis.Redis(
                    host=self.config.get("REDIS_HOST"),
                    
port=self.config.get("REDIS_PORT"),
                    password=self.config.get("REDIS_PASSWORD"),
                    ssl=True,
                )
docstore = RedisDocumentStore.from_redis_client(
                    redis_client=redis_client,
                    namespace=namespace
                )
storage_context = StorageContext.from_defaults(
                    docstore=self.docstore,
                    index_store=RedisIndexStore.from_redis_client(
                        redis_client=redis_client,
                        namespace=namespace
                    ),
                )
 

after this I reload the index from the storage context like below:
base_index = load_index_from_storage(storage_context)

when setting this up and loading the index like after I close my app:
Plain Text
try:
 indices = load_indices_from_storage(self.storage_context)
                   for index in indices:
                        print(index.index_id)
                    base_index = load_index_from_storage(storage_context)
                    print("[INFO] Index found at storage")
                except ValueError as e:
                    print("[INFO] No index found at storage")
                    base_index = VectorStoreIndex(
                        nodes=[],               storage_context=storage_context)

and the retrieval is defined as:

Plain Text
base_retriever = base_index.as_retriever(
                similarity_top_k=self.similarity_top_k
            )
            retriever = AutoMergingRetriever(
                base_retriever, self.storage_context, verbose=True
            )
              query_bundle = QueryBundle(query_str=query)
            retrived_nodes = retriever.retrieve(query_bundle)
           

this outputs empty retrieved nodes for some reason.
L
b
49 comments
I replied on github, but you seem to missing configuration for a vector store in your storage context πŸ‘€
Sorry must've missed it
@Logan M Could I use any vector store?
I tried using the legacy RedisVectorStore first but the primary disadvantage is my redis instance is on upsert and since the legacy initialization requires a redis url and not the redis client that I've been using for docstore and index store:

Plain Text
self.redis_client = redis.Redis(
                    host=self.config.get("UPSTASH_REDIS_HOST"),
                    port=self.config.get("UPSTASH_REDIS_PORT"),
                    password=self.config.get("UPSTASH_REDIS_PASSWORD"),
                    ssl=True,
                )

so the Redis Vector Store returns

MODULE not supported
and I also tried the UpstashVectorStore
you can use any vector store indeed πŸ‘€
this throws a type error for some reason
Plain Text
Can't instantiate abstract class BaseNode with abstract methods get_content, get_metadata_str, get_type, hash, set_content (type=type_error)
Here the storage context was:

Plain Text
self.redis_client = redis.Redis(
                    host=self.config.get("UPSTASH_REDIS_HOST"),
                    port=self.config.get("UPSTASH_REDIS_PORT"),
                    password=self.config.get("UPSTASH_REDIS_PASSWORD"),
                    ssl=True,
                )
                self.docstore = RedisDocumentStore.from_redis_client(
                    redis_client=self.redis_client,
                    namespace=self.namespace
                )
                self.vector_store = UpstashVectorStore(
                    url=self.config.get("UPSTASH_VECTOR_URL"),
                    token=self.config.get("UPSTASH_VECTOR_TOKEN"),
                )

                self.storage_context = StorageContext.from_defaults(
                    docstore=self.docstore,
                    index_store=RedisIndexStore.from_redis_client(
                        redis_client=self.redis_client,
                        namespace=self.namespace
                    ),
                    vector_store=self.vector_store
                )
Oooo thats a venv issue πŸ‘€ Or at least 90% sure it is. Or you are mixing legacy imports with other newer imports
how do I fix it?
from llama_index.legacy.vector_stores.upstash import UpstashVectorStore
this is the import for Upstash right?
Was using a similar one for redis too:

from llama_index.legacy.vector_stores.redis import RedisVectorStore
Plain Text
pip install llama-index-vector-stores-upstash


from llama_index.vector_stores.uptash import UpstashVectorStore
so once I do this
it should work πŸ™‚
Plain Text
try:
                    indices = load_indices_from_storage(self.storage_context)
                    for index in indices:
                        print(index.index_id)
                    self.base_index = load_index_from_storage(self.storage_context)
                    print(self.base_index)
                    print("[INFO] Index found at storage")
                except ValueError as e:
                    print("[INFO] No index found at storage")
                    self.base_index = VectorStoreIndex(
                        nodes=[],
                        storage_context=self.storage_context,
                    )
the loading would look somewhat like this right>
the rest would be auto fetched from storage context
Yea pretty much! Although since you are using a vector store integration, normally all the storage is put into the vector store to simplify, so you'd want to override that with this
pip install llama-index-vector-stores-upstash

Is there something like this even for the newer redis store?
VectorStoreIndex(...., store_nodes_override=True)
There is a redis one, but I'm not sure it will solve your issue (it seems like you want to be able to pass the client in right?)
I formed the rediss url manually seeing my redis client initialization :

Plain Text
self.redis_client = redis.Redis(
                    host=self.config.get("UPSTASH_REDIS_HOST"),
                    port=self.config.get("UPSTASH_REDIS_PORT"),
                    password=self.config.get("UPSTASH_REDIS_PASSWORD"),
                    ssl=True,
                )


but that seems to throw an error from the upstash end
btw is there a list for these newer imports like the upstash one you shared?
Would love to have one handy
There is this package registry
https://discord.com/channels/1059199217496772688/1073670729054294197/1207845501660168232

We are also in the process of updating https://llamahub.ai -- most packages are there, each card should show the install and import (we need to flesh this out more over time)
did the pip install

pip install llama-index-vector-stores-upstash
the import still seems to fail :

from llama_index.vector_stores.uptash import UpstashVectorStore
Typo: from llama_index.vector_stores.upstash import UpstashVectorStore
I think I wrote that earlier and then edited haha
Seems alright now
works awesome!!! πŸ™Œ
couldn't sleep last night because of this vector store integration πŸ˜„
Thank you @Logan M
Is there some visualisation and tacking integration that I can add that better helps visualise the embeddings created and the end to end chunking and retrieval logic?
hmm, not quite at the moment! There are observability integrations (like arize) which will show traces, but not quite the same I think
Something to look forward to then
Add a reply
Sign up and join the conversation on Discord