Add 'get_document' attribute to 'SupabaseVectorStore' #10692
Replies: 1 comment
-
🤖 Hey @rahulkrprajapati, great to see you back! How's everything going with your LlamaIndex adventures? Sure, I can guide you on how to add a 'get_document' function to the 'SupabaseVectorStore' class in your LlamaIndex application. You can use the 'get_by_id' method as a base. This method queries the collection for a document with a specific id. However, instead of returning just the row ids, you would want to return the entire document. Here's how you can do it: def get_document(self, doc_id: str, **kwargs: Any) -> Any:
"""Get document by doc id.
Args:
doc_id (str): document id
"""
filters = {"doc_id": {"$eq": doc_id}}
results = self._collection.query(
data=None,
filters=filters,
include_value=True,
include_metadata=True,
**kwargs,
)
if len(results) > 0:
id_, distance, metadata = results[0]
text = metadata.pop("text", None)
try:
node = metadata_dict_to_node(metadata)
except Exception:
# NOTE: deprecated legacy logic for backward compatibility
metadata, node_info, relationships = legacy_metadata_dict_to_node(
metadata
)
node = TextNode(
id_=id_,
text=text,
metadata=metadata,
start_char_idx=node_info.get("start", None),
end_char_idx=node_info.get("end", None),
relationships=relationships,
)
return node
return None This function will return the first document that matches the provided id. If no document is found, it will return None. The document is returned as a 'TextNode' object, which includes the document's id, text, metadata, start and end character indices, and relationships. Please note that the 'TextNode' object is not defined in the LlamaIndex repository. You might need to define it in your application or use an equivalent object that suits your needs. You can find more details about the 'SupabaseVectorStore' class in the llama_index/vector_stores/supabase.py file in the LlamaIndex repository. Let me know if you need further assistance. Sources
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
How do I
get_document
function to SupabaseVectorStore class.Beta Was this translation helpful? Give feedback.
All reactions