Closed JINO-ROHIT closed 2 months ago
The error "list object has no attribute _id" suggests that somewhere in your code, you are trying to access an attribute _id
on a list object instead of on an individual BaseNode
object. To resolve this, ensure that you are correctly accessing the attributes of the BaseNode
objects in your list.
Here is a corrected version of your code snippet, focusing on the _build_points
method and ensuring that you are correctly iterating over the nodes and accessing their attributes:
def _build_points(self, nodes: List[BaseNode], sparse_vector_name: str) -> Tuple[List[Any], List[str]]:
from qdrant_client.http import models as rest
ids = []
points = []
for node_batch in iter_batch(nodes, self.batch_size):
node_ids = []
vectors: List[Any] = []
sparse_vectors: List[List[float]] = []
sparse_indices: List[List[int]] = []
payloads = []
if self.enable_hybrid and self._sparse_doc_fn is not None:
sparse_indices, sparse_vectors = self._sparse_doc_fn(
[
node.get_content(metadata_mode=MetadataMode.EMBED)
for node in node_batch
],
)
for i, node in enumerate(node_batch):
assert isinstance(node, BaseNode)
node_ids.append(node.node_id)
if self.enable_hybrid:
if (
len(sparse_vectors) > 0
and len(sparse_indices) > 0
and len(sparse_vectors) == len(sparse_indices)
):
vectors.append(
{
"text-sparse": rest.SparseVector(
indices=sparse_indices[i],
values=sparse_vectors[i],
),
"text-dense": node.get_embedding(),
}
)
else:
vectors.append(
{
"text-dense": node.get_embedding(),
}
)
else:
vectors.append(node.get_embedding())
metadata = node_to_metadata_dict(
node, remove_text=False, flat_metadata=self.flat_metadata
)
payloads.append(metadata)
points.extend(
[
rest.PointStruct(id=node_id, payload=payload, vector=vector)
for node_id, payload, vector in zip(node_ids, payloads, vectors)
]
)
ids.extend(node_ids)
return points, ids
Ensure that you are calling this method correctly and passing a list of BaseNode
objects. The node_ids.append(node.node_id)
line correctly accesses the node_id
attribute of each BaseNode
object.
Additionally, if you encounter an error like "AttributeError: 'ScoredPoint' object has no attribute 'get'", it might be related to how the query results are being processed. Make sure that the objects returned by the query are being handled correctly and that you are not mistakenly treating a list or another type of object as if it were a BaseNode
.
For example, the parse_to_query_result
method converts the vector store response to VectorStoreQueryResult
and ensures that the nodes are correctly parsed:
def parse_to_query_result(self, response: List[Any]) -> VectorStoreQueryResult:
nodes = []
similarities = []
ids = []
for point in response:
payload = cast(Payload, point.payload)
try:
node = metadata_dict_to_node(payload)
except Exception:
metadata, node_info, relationships = legacy_metadata_dict_to_node(payload)
node = TextNode(
id_=str(point.id),
text=payload.get("text"),
metadata=metadata,
start_char_idx=node_info.get("start", None),
end_char_idx=node_info.get("end", None),
relationships=relationships,
)
nodes.append(node)
ids.append(str(point.id))
try:
similarities.append(point.score)
except AttributeError:
similarities.append(1.0)
return VectorStoreQueryResult(nodes=nodes, similarities=similarities, ids=ids)
Make sure that your code correctly handles the response from Qdrant and processes each BaseNode
object individually [1][2][3].
To continue talking to Dosu, mention @dosu.
Question Validation
Question
im getting an error while trying to index nodes with qdrant, please help. Attaching my code snippet below-
class FileReader: def init(self, file_paths): self.file_paths = file_paths
class VectorIndexer: def init(self, nodes, vector_store, embedding_model): self.nodes = nodes self.vector_store = vector_store self.embedding_model = embedding_model
def main():
if name == "main": main()