Visualize Embeddings as a 3d Plotly scatter plot from Redis Vector Store #12168
Replies: 1 comment 6 replies
-
Hey @rahulkrprajapati! Great to see you diving into another exciting project with us. 🚀 To visualize the embeddings from a
Here's an example code snippet that demonstrates these steps: import plotly.graph_objects as go
from llama_index.core.vector_stores.types import VectorStoreQuery
# Assuming `redis_vector_store` is an instance of RedisVectorStore
# and `query_embedding` is your query vector
# Step 1: Query the RedisVectorStore for embeddings
query = VectorStoreQuery(query_embedding=query_embedding, similarity_top_k=10)
query_result = redis_vector_store.query(query)
# Step 2: Extract embeddings and IDs
# This step assumes embeddings are directly usable; adjust as necessary
ids = [node.id for node in query_result.nodes]
embeddings = [node.get_embedding() for node in query_result.nodes] # Adjust this line based on how embeddings are stored
# Convert embeddings into x, y, z lists for Plotly
x = [embedding[0] for embedding in embeddings]
y = [embedding[1] for embedding in embeddings]
z = [embedding[2] for embedding in embeddings]
# Step 3: Prepare Data for Plotly
# Already done above by extracting x, y, z
# Step 4: Create a 3D Scatter Plot with Plotly
fig = go.Figure(data=[go.Scatter3d(x=x, y=y, z=z, mode='markers',
marker=dict(size=5),
text=ids)]) # Use IDs as hover text
# Customize the layout
fig.update_layout(title='3D Scatter Plot of Embeddings',
scene=dict(xaxis_title='X',
yaxis_title='Y',
zaxis_title='Z'))
fig.show() This example assumes that the embeddings are 3-dimensional and directly usable after retrieval. If the embeddings are stored in a different format (e.g., as buffers), you'll need to convert them to a usable format before plotting. Additionally, adjust the For more details on how the Sources
|
Beta Was this translation helpful? Give feedback.
-
How do I visualize the embeddings as a 3d plot using plotly. My vector store is defined as:
vector_store = RedisVectorStore(
index_name=namespace,
redis_url=self.config.get('REDIS_VECTOR_STORE'),
metadata_fields=['namespace']
)
Beta Was this translation helpful? Give feedback.
All reactions