-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmemory.docs.retry-embed.py
More file actions
40 lines (27 loc) · 988 Bytes
/
memory.docs.retry-embed.py
File metadata and controls
40 lines (27 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
Example demonstrating how to retry embedding for documents in a memory in Langbase.
"""
import json
import os
from dotenv import load_dotenv
from langbase import Langbase
def main():
load_dotenv()
# Get API key from environment variable
langbase_api_key = os.getenv("LANGBASE_API_KEY")
# Initialize the client
langbase = Langbase(api_key=langbase_api_key)
# Memory name to retry embedding for
memory_name = "product-knowledge" # Replace with your memory name
document_name = "name.txt" # Replace with document name
# Retry embedding for failed documents
try:
response = langbase.memories.documents.embeddings.retry(
memory_name=memory_name, document_name=document_name
)
print(f"Retry embedding initiated for memory '{memory_name}'")
print(json.dumps(response, indent=2))
except Exception as e:
print(f"Error retrying embedding: {e}")
if __name__ == "__main__":
main()