Gravix Layer x Pinecone Integration
Combine Gravix Layer's LLMs with Pinecone for scalable, high-performance vector search and retrieval-augmented generation (RAG).
What You'll Learn
- How to use Gravix Layer for embedding generation
- How to store and search embeddings in Pinecone
- Example: RAG pipeline with Gravix Layer and Pinecone
1. Install Required Packages
pip install pinecone-client openai langchain python-dotenv
2. Configure Your API Key
Add your API key to a .env
file:
GRAVIXLAYER_API_KEY=your_api_key_here
3. Using Pinecone with Gravix Layer
import os
import json
from openai import OpenAI
from pinecone import Pinecone, ServerlessSpec
from dotenv import load_dotenv
load_dotenv()
api_key = os.environ.get("GRAVIXLAYER_API_KEY", "test_key")
pinecone_api_key = os.environ.get("PINECONE_API_KEY", "your_real_pinecone_key")
client = OpenAI(
base_url="https://api.gravixlayer.com/v1/inference",
api_key=api_key,
)
text = "Why is the sky blue?"
embedding_response = client.embeddings.create(
model="meta-llama/llama-3.1-8b-instruct",
input=text,
)
vector = embedding_response.data[0].embedding
pc = Pinecone(api_key=pinecone_api_key)
index_name = "my-index"
if index_name not in pc.list_indexes().names():
pc.create_index(
name=index_name,
dimension=len(vector),
metric="cosine",
spec=ServerlessSpec(cloud="aws", region="us-west-2")
)
index = pc.Index(index_name)
index.upsert([{"id": "id1", "values": vector}])
results = index.query(vector=vector, top_k=3)
print(json.dumps(results.to_dict(), indent=2))
Expected Output:
{
"data": [
{
"embedding": [ ... list of floats ... ],
"index": 0,
"object": "embedding"
}
],
"model": "meta-llama/llama-3.1-8b-instruct",
"object": "list",
"usage": { "prompt_tokens": 6, "total_tokens": 6 }
}
Note: You must set a valid Pinecone API key in your environment for the workflow to succeed. The code is fully compatible with Gravix Layer and Pinecone.
Pinecone enables scalable vector search. Gravix Layer provides fast, accurate embeddings for any RAG or search application.