Closed ritzshah closed 2 months ago
Hey @ritzshah, I'm here to assist you with the issue you've encountered. I'm a bot designed to help with bug fixes, answer questions, and guide you through becoming a contributor. Let's tackle this together!
To resolve the error "'CacheMiss' object has no attribute 'get'" when trying to build a vertex in the Langflow application using PGVector with PostgreSQL, ensure that the inputs
parameter is correctly passed and handled. The error suggests an issue with how the inputs
parameter is being accessed or used.
Here is the relevant code snippet from the PGVectorComponent
class:
def build(
self,
embedding: Embeddings,
pg_server_url: str,
collection_name: str,
inputs: Optional[Record] = None,
) -> Union[VectorStore, BaseRetriever]:
documents = []
for _input in inputs or []:
if isinstance(_input, Record):
documents.append(_input.to_lc_document())
else:
documents.append(_input)
try:
if documents is None:
vector_store = PGVector.from_existing_index(
embedding=embedding,
collection_name=collection_name,
connection_string=pg_server_url,
)
else:
vector_store = PGVector.from_documents(
embedding=embedding,
documents=documents, # type: ignore
collection_name=collection_name,
connection_string=pg_server_url,
)
except Exception as e:
raise RuntimeError(f"Failed to build PGVector: {e}")
return vector_store
Ensure that the inputs
parameter is correctly passed as a list of Record
objects. The inputs
parameter should not be None
or an incorrect type that does not have the required attributes.
If the inputs
parameter is being fetched from a cache or another source, make sure that the fetched object is indeed a list of Record
objects and not a CacheMiss
object or any other type that does not have the required attributes.
Here is an example of how you might call the build
method correctly:
embedding = ... # Your Embeddings object
pg_server_url = "your_postgresql_server_url"
collection_name = "your_collection_name"
inputs = [...] # A list of Record objects
pg_vector_component = PGVectorComponent()
vector_store = pg_vector_component.build(
embedding=embedding,
pg_server_url=pg_server_url,
collection_name=collection_name,
inputs=inputs
)
Make sure that inputs
is a list of Record
objects and not None
or any other incorrect type. Additionally, refer to the Langflow documentation for more details on the correct usage and configuration of the PGVectorComponent
[1][2][3].
To continue talking to Dosu, mention @dosu.
Hi Thanks for response @Dosu
I see that the Ollama Embeddings have output None and maybe that is causing issue.. When I run the Ollama Embeddings I get this validation error.
For further information visit https://errors.pydantic.dev/2.7/v/missing
[06/03/24 11:40:17] ERROR 2024-06-03 11:40:17 - ERROR - utils - Error logging transaction: 4 validation errors for TransactionModel utils.py:200
flow_id
Field required
For further information visit https://errors.pydantic.dev/2.7/v/missing
source
Field required
For further information visit https://errors.pydantic.dev/2.7/v/missing
target
Field required
For further information visit https://errors.pydantic.dev/2.7/v/missing
target_args
Field required
For further information visit https://errors.pydantic.dev/2.7/v/missing
I see that the ollama model is running.
ollama ps
NAME ID SIZE PROCESSOR UNTIL
sroecker/granite-7b-lab:latest 206d6e1e0e42 5.9 GB 100% GPU 4 minutes from now
This is snapshot from langflow
Any suggestions as I am providing proper url and the model name as well as temperature but I see output as None which is going as Embedding input to PGVector. Is this an issue and how to fix this?
To fix the issue with the Ollama Embeddings component outputting None
, ensure that the OllamaEmbeddings
object is correctly instantiated and that the API connection is successful. Here is the relevant code snippet from the OllamaEmbeddingsComponent
class:
from typing import Optional
from langflow import CustomComponent
from langchain.embeddings.base import Embeddings
from langchain_community.embeddings import OllamaEmbeddings
class OllamaEmbeddingsComponent(CustomComponent):
display_name: str = "Ollama Embeddings"
description: str = "Embeddings model from Ollama."
documentation = "https://python.langchain.com/docs/integrations/text_embedding/ollama"
beta = True
def build_config(self):
return {
"model": {
"display_name": "Ollama Model",
},
"base_url": {"display_name": "Ollama Base URL"},
"temperature": {"display_name": "Model Temperature"},
"code": {"show": False},
}
def build(
self,
model: str = "llama2",
base_url: str = "http://localhost:11434",
temperature: Optional[float] = None,
) -> Embeddings:
try:
output = OllamaEmbeddings(model=model, base_url=base_url, temperature=temperature) # type: ignore
except Exception as e:
raise ValueError("Could not connect to Ollama API.") from e
return output
Ensure that:
model
, base_url
, and temperature
parameters are correctly set and valid.base_url
.OllamaEmbeddings
class is correctly imported and used.If the API connection fails, the ValueError
will be raised, indicating the connection issue. You can add logging to capture more details about the exception:
import logging
def build(
self,
model: str = "llama2",
base_url: str = "http://localhost:11434",
temperature: Optional[float] = None,
) -> Embeddings:
try:
output = OllamaEmbeddings(model=model, base_url=base_url, temperature=temperature) # type: ignore
except Exception as e:
logging.error(f"Failed to connect to Ollama API: {e}")
raise ValueError("Could not connect to Ollama API.") from e
return output
This will help you diagnose why the embeddings might be None
and ensure the component outputs valid embeddings [1][2].
To continue talking to Dosu, mention @dosu.
Can you provide details here on what should be the connection string for postgres PGVector DB access using PGVEctor DB Store for storing the embeddings.
To correctly set up a connection string for PostgreSQL PGVector DB access and ensure that embeddings are correctly stored, follow these steps:
Define the Connection String: Ensure that your PostgreSQL server connection string is correctly formatted. It should look something like this:
postgresql://username:password@hostname:port/database
Set Up the PGVectorComponent: Use the PGVectorComponent
class to build the vector store. Here is an example of how to use it:
from langchain.embeddings.base import Embeddings
from langflow.schema import Record
from your_module import PGVectorComponent # Adjust the import based on your module structure
# Example embedding object
embedding = Embeddings()
# PostgreSQL server connection string
pg_server_url = "postgresql://username:password@hostname:port/database"
# Name of the table to store the vectors
collection_name = "your_table_name"
# Optional: List of documents to store
documents = [Record(content="Your document content")]
# Initialize the PGVectorComponent
pg_vector_component = PGVectorComponent()
# Build the vector store
try:
vector_store = pg_vector_component.build(
embedding=embedding,
pg_server_url=pg_server_url,
collection_name=collection_name,
inputs=documents # Optional
)
except RuntimeError as e:
print(f"Error: {e}")
Handle Errors: The build
method in the PGVectorComponent
class already includes error handling. If there is an issue with building the vector store, it will raise a RuntimeError
with the appropriate message.
By following these steps, you can ensure that your connection string is correctly set up and that embeddings are correctly stored in the PostgreSQL PGVector DB. The PGVectorComponent
class handles the conversion of inputs to the appropriate document format and manages the connection to the PostgreSQL server, ensuring a smooth setup process [1][2][3].
To continue talking to Dosu, mention @dosu.
Hello, Sorry for the delay. Did you try using the new version? Does the error still persist?
Hi @ritzshah , I hope you're doing well. Just a friendly reminder that if we do not hear back from you within the next 3 days, we will close this issue. If you need more time or further assistance, please let us know.
Thank you for your understanding!
Thank you for your contribution! This issue will be closed. If you have any questions or encounter another problem, please open a new issue and we will be ready to assist you.
Describe the bug A clear and concise description of what the bug is. While implementing a Vector Store using PostgreSQL (PGVector) connecting to localhost:5432, get error "'CacheMiss' object has no attribute 'get'"
Browser and Version
Browser [e.g. chrome, safari] - Google Chrome
Version [e.g. 22] - 124.0.6367.210
Langflow version - v1.0.0a43...
To Reproduce Steps to reproduce the behavior:
& this is the error message
Screenshots If applicable, add screenshots to help explain your problem.
Error message on langflow terminal venv/venv310/lib/python3.10/site-packages/langchain_community/vectorstores/pgvector.py:322: LangChainPendingDeprecationWarning: Please use JSONB instead of JSON for metadata. This change will allow for more efficient querying that involves filtering based on metadata.Please note that filtering operators have been changed when using JSOB metadata to be prefixed with a $ sign to avoid name collisions with columns. If you're using an existing database, you will need to create adb migration for your metadata column to be JSONB and update your queries to use the new operators. warn_deprecated( objc[34747]: +[NSCFConstantString initialize] may have been in progress in another thread when fork() was called. objc[34747]: +[NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug. [06/03/24 11:09:10] ERROR 2024-06-03 11:09:10 - ERROR - glogging - Worker (pid:34747) was sent SIGABRT! glogging.py:272 Starting Langflow v1.0.0a41... [06/03/24 11:09:14] ERROR 2024-06-03 11:09:14 - ERROR - chat - Error building vertex: 'CacheMiss' object has no attribute 'get' chat.py:232 ERROR 2024-06-03 11:09:14 - ERROR - chat - 'CacheMiss' object has no attribute 'get' chat.py:233 Traceback (most recent call last):
Additional context Add any other context about the problem here.