This project demonstrates how to perform vector embeddings on JSON data using a Language Model (LLM), store the embeddings in Pinecone, and enable semantic search and retrieval.
- Python 3.8+
- Pinecone account
- OpenAI API key (or alternative LLM provider)
- Required Python libraries:
pinecone-clientgemininode
- Clone the repository:
git clone https://github.com/CodingWithTashi/json-vector-embedder.git
cd json-vector-embedder- Install dependencies:
npm i- Set up environment variables:
NEXT_PUBLIC_PINECONE_API_KEY=key
NEXT_PUBLIC_PINECONE_INDEX=key
NEXT_PUBLIC_GOOGLE_API_KEY=keyimport json
import inpuDataList from "../../example.data.json";
export async function loadInputData(): Promise<InputData[]> {
try {
if (inpuDataList.length === 0) {
throw new Error("No data found in the JSON file");
} else if (inpuDataList.length == 1 && inpuDataList[0].type === "test") {
throw new Error("Add actual json data to example.data.json");
} else {
return inpuDataList as InputData[];
}
} catch (error) {
console.error("Error loading or parsing JSON file:", error);
throw error;
}
}await PineconeStore.fromDocuments(docs, embeddings, {
pineconeIndex: index,
namespace: "monastery_data", // Added specific namespace
});
const vectorQueryResponse = await pineconeIndex
.namespace("monastery_data")
.query({
vector: embedding,
topK: 4,
includeMetadata: true,
});
Contributions are welcome! Please submit a pull request or open an issue.
- Pinecone
- OpenAI/Gemini