0

I have successfully implemented the "create" and "askquestion" LangChain API endpoints, which are working as expected. However, I am facing challenges with the "update," "delete," and "view" functionalities.

I am using LangChain in conjunction with Vector db, pinecone for local storage, Python Flask for API development, and OpenAI for chat completion and embeddings.

Specifically, I am encountering difficulties with the following functionalities:

  • Update: I am unable to update a particular title or content based on the provided ID. The update should include modifying the content as well as updating the associated embeddings.

  • Delete: I need assistance in implementing the deletion of a specific entry, including both the title and content, along with its corresponding embeddings.

  • View: I am unable to retrieve and display the ID, title, and content in the response.

How could I implement the desired functionalities correctly?

from flask import Flask, request, jsonify
import uuid
import os
from langchain.llms import AzureOpenAI
from langchain.embeddings.openai import OpenAIEmbeddings
import openai
from langchain.vectorstores import Pinecone
import pinecone

pinecone.init(api_key=PINECONE_API_KEY, environment=PINECONE_API_ENV)
index_name = "knowledge-base"
index = pinecone.Index(index_name)
print(index.describe_index_stats())
# pinecone.deinit()

app = Flask(__name__)

knowledge_base = []


@app.route("/add", methods=["POST"])
def add_entry():
    data = request.get_json()
    title = data["title"]
    content = data["content"]

    entry_id = str(uuid.uuid4())

    embeddings = OpenAIEmbeddings(
        deployment="embedding-ada-002", model="text-embedding-ada-002")
    pinecone.init(api_key=PINECONE_API_KEY, environment=PINECONE_API_ENV)
    vectorstore = Pinecone.from_texts(
        [content], embeddings, index_name=index_name, namespace="knowledge")
    # pinecone.deinit()

    entry = {"id": entry_id, "title": title, "content": content}
    knowledge_base.append(entry)

    return jsonify(entry)
mkrieger1
  • 19,194
  • 5
  • 54
  • 65

0 Answers0