Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions dev-ai-app-dev-gaming/build/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ Before answering questions, we need to prepare the data by vectoring the claims
- Stores Recommendations: Inserts the full recommendation text (from previous cell) as a single chunk if not already present.
- We delete prior chunks for this authorization.
- We use `VECTOR_CHUNKS` to split the recommendation text.
- The chunks will be inserted into `GAMING_CHUNK`
- The chunks will be inserted into `GAM_CHUNK`
- We display a data frame summary to show the chunks.


Expand All @@ -371,15 +371,15 @@ Before answering questions, we need to prepare the data by vectoring the claims
text_to_chunk = f"SuggestedAction: {table_status}\nRationale: (empty model output)."

# 0) Clear old chunks for this request
cursor.execute("DELETE FROM GAMING_CHUNKS WHERE REQUEST_ID = :rid", {'rid': req_id})
cursor.execute("DELETE FROM GAM_CHUNKS WHERE REQUEST_ID = :rid", {'rid': req_id})
connection.commit()

# 1) Chunk via VECTOR_CHUNKS
chunk_size = 25
overlap = 0

insert_chunks_sql = f"""
INSERT INTO GAMING_CHUNKS (CHUNK_ID, REQUEST_ID, CHUNK_TEXT)
INSERT INTO GAM_CHUNKS (CHUNK_ID, REQUEST_ID, CHUNK_TEXT)
SELECT c.chunk_offset, :rid, c.chunk_text
FROM (SELECT :txt AS c FROM dual) s,
VECTOR_CHUNKS(
Expand Down Expand Up @@ -407,7 +407,7 @@ Before answering questions, we need to prepare the data by vectoring the claims
# 2) Fetch & SHOW the chunks
cursor.execute("""
SELECT c.CHUNK_ID, c.CHUNK_TEXT
FROM GAMING_CHUNKS c
FROM GAM_CHUNKS c
WHERE c.REQUEST_ID = :rid
ORDER BY c.CHUNK_ID
""", {'rid': req_id})
Expand Down Expand Up @@ -455,21 +455,21 @@ In this step:

- **Generates Embeddings**: This is a new feature in Oracle Database 23ai that allows you to create embeddings directly within the database, eliminating the need for external tools or APIs. The `dbms_vector_chain.utl_to_embedding` function takes the recommendation text as input and returns an embedding vector.

- **Stores Embeddings**: We update `GAMING_CHUNK.CHUNK_VECTOR` by embedding each `CHUNK_TEXT` using `dbms_vector_chain.utl_to_embedding` with `DEMO_MODEL`. A short verification output is printed.
- **Stores Embeddings**: We update `GAM_CHUNK.CHUNK_VECTOR` by embedding each `CHUNK_TEXT` using `dbms_vector_chain.utl_to_embedding` with `DEMO_MODEL`. A short verification output is printed.

1. Copy the following code into a new cell block:

```python
<copy>
# 🔹 Task 6: Create embeddings for GAMING_CHUNKS rows
# 🔹 Task 6: Create embeddings for GAM_CHUNKS rows
req_id = request_id # from Task 4/5
vp = json.dumps({"provider": "database", "model": "DEMO_MODEL", "dimensions": 384})

# 1) Embed all chunks for this Gaming request
try:
cursor.execute(
"""
UPDATE GAMING_CHUNKS c
UPDATE GAM_CHUNKS c
SET c.CHUNK_VECTOR = dbms_vector_chain.utl_to_embedding(c.CHUNK_TEXT, JSON(:vp))
WHERE c.REQUEST_ID = :rid
""",
Expand All @@ -486,15 +486,15 @@ In this step:
# 2) Sanity check: how many rows have vectors now?
cursor.execute("""
SELECT COUNT(*)
FROM GAMING_CHUNKS c
FROM GAM_CHUNKS c
WHERE c.REQUEST_ID = :rid
AND c.CHUNK_VECTOR IS NOT NULL
""", {"rid": req_id})
have_vec = cursor.fetchone()[0]

cursor.execute("""
SELECT COUNT(*)
FROM GAMING_CHUNKS c
FROM GAM_CHUNKS c
WHERE c.REQUEST_ID = :rid
""", {"rid": req_id})
total_rows = cursor.fetchone()[0]
Expand Down Expand Up @@ -547,12 +547,12 @@ Now that the recommendations are vectorized, we can process a user’s question:
)
qvec = cursor.fetchone()[0]

# 2) Retrieve chunks from GAMING_CHUNKS for this request
# 2) Retrieve chunks from GAM_CHUNKS for this request
cursor.execute(f"""
SELECT c.CHUNK_ID,
c.CHUNK_TEXT,
VECTOR_DISTANCE(c.CHUNK_VECTOR, :qv, COSINE) AS dist
FROM GAMING_CHUNKS c
FROM GAM_CHUNKS c
WHERE c.REQUEST_ID = :rid
AND c.CHUNK_VECTOR IS NOT NULL
ORDER BY dist
Expand Down