Setup
- Install Langtrace’s SDK and initialize the SDK in your code.
Python
Typescript
- Setup environment variables:
Shell
Usage
Generate a simple output with your deployment’s model:
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Pinecone is a vector database that enables fast and accurate vector search for building AI applications. It provides the infrastructure for the long-term memory and retrieval needed to develop state-of-the-art AI systems.
# Install the SDK
pip install -U langtrace-python-sdk pinecone
npm install @pinecone-database/pinecone-client
export LANGTRACE_API_KEY=YOUR_LANGTRACE_API_KEY
export PINECONE_API_KEY=YOUR_PINECONE_API_KEY
import os
from langtrace_python_sdk import langtrace # Must precede any llm module imports
langtrace.init(api_key = os.environ['LANGTRACE_API_KEY'])
from pinecone import Pinecone, ServerlessSpec
pc = Pinecone(api_key=os.environ['PINECONE_API_KEY'])
# Create an Index and upsert some data in Pinecone:
pc.create_index(
name="index",
dimension=8, # Replace with your model dimensions
metric="euclidean", # Replace with your model metric
spec=ServerlessSpec(
cloud="aws",
region="us-east-1"
)
)
index = pc.Index("index")
index.upsert(
vectors=[
{"id": "A", "values": [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]},
{"id": "B", "values": [0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2]},
{"id": "C", "values": [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]},
{"id": "D", "values": [0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4]}
]
)
import { init as langtraceInit } from 'langtrase/typescript-sdk';
import { PineconeClient, ServerlessSpec } from '@pinecone-database/pinecone-client';
langtraceInit({
apiKey: langtraceApiKey,
});
// Step 3: Initialize Pinecone client
const pinecone = new PineconeClient({
apiKey: pineconeApiKey,
});
// Step 4: Create an Index and upsert some data in Pinecone
(async () => {
await pinecone.createIndex({
name: "index",
dimension: 8, // Replace with your model dimensions
metric: "euclidean", // Replace with your model metric
spec: new ServerlessSpec({
cloud: "aws",
region: "us-east-1",
}),
});
const index = pinecone.Index("index");
await index.upsert({
vectors: [
{ id: "A", values: [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1] },
{ id: "B", values: [0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2] },
{ id: "C", values: [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3] },
{ id: "D", values: [0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4] },
],
});
})();
